Here is an example using the HTTPService object. You should be able to use the same steps on a method that returns an AsyncToken.
var asyncToken:AsyncToken; var internalIResponder:IResponder; ... asyncToken = _httpService.send(); internalIResponder = new AsyncResponder(onHTTPServiceSuccess, onHTTPServiceFault, asyncToken); asyncToken.addResponder(internalIResponder);
When send is called it will return an AsyncToken. We can attach an IResponder object to the AsyncToken that will handle the success and fail cases for the response.
Ever had a look at Cairngorm?
ReplyDeleteCairngorm is using IResponders exclusively since a long time.
I've heard of it, but never used it on a project. I'd like to check it out at some point.
ReplyDeleteYou can also do in your listening function :
ReplyDeletesrv.removeEventListener( theListenedEvent, theListeningFunction);
You can remove the listener if it is a member/field variable. If it's local to the method you can't remove it later.
ReplyDeleteThank you. I was having this exact problem (multiple listeners being called from HTTPService result). I had tried using removeEventListener, but when you're firing off a bunch of asynchronous requests, you might inadvertently remove the listener before another async request has started/completed.
ReplyDeleteGreat tips really enjoying it
ReplyDelete