我正在尝试RestClientLib,但我添加的事件侦听器没有被激发。我不明白为什么。有人有什么想法吗?
var restClient = new RestClient();
protected function btnInfo2_clickHandler(event:MouseEvent):void
{
restClient.host = "somehost";
restClient.port = "443";
restClient.secure = true;
restClient.setupRequest(RestClient.METHOD_GET, "somemethod");
restClient.addparam("format","json");
restClient.addEventListener(RestEvent.RESULT, onResult);
restClient.sendrequest();
}
protected function onResult(event:RestEvent):void
{
trace("onResult");
}
如果我在RestClient:的源中放入断点
private function onResult(event:ResultEvent,token:Object=null):void
{
trace("Reached onResult handler");
var rawData:String = String(event.result);
event.token.dispatchEvent(new RestEvent(RestEvent.RESULT, RestClient.SUCCESS, rawData,event.statusCode,null,event.token, true));
}
实际接收到数据,但不传播事件。
我也尝试过将气泡设置为真,但没有用。
看起来事件是在event.token上调度的。这个令牌看起来像是由sendrequest方法返回的。所以你应该添加这样的监听器:
var token:AsyncToken = restClient.sendrequest();
token.addEventListener(RestEvent.RESULT, onResult);
希望能奏效。