Using addEventListener
is a popular way of of waiting for a
response from a server. I've run into issues using this when a server
returns the same response for all methods. Many of the listener methods
are tripped for the wrong response. The easy way to avoid this is to use
an IResponder
.
Here is an example using the HTTPService object. You should be able to
use the same steps on a method that returns an AsyncToken.
1.var asyncToken:AsyncToken;<br />2.var internalIResponder:IResponder;<br />3....<br />4.asyncToken = _httpService.send();<br />5.internalIResponder = new AsyncResponder(onHTTPServiceSuccess, onHTTPServiceFault, asyncToken);<br />6.asyncToken.addResponder(internalIResponder);<br />
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.