views:

305

answers:

3

OK I have an HTTPService that executes the dataLoaded(e:ResultEvent):void function whenever it gets a result from a send() call.

OK so If I call HTTPService.send() and then call HTTPService.send() again before the previous one receives a result, I end up repeatedly running dataLoaded() which is undesirable

What I want is if HTTPService.send() gets called before a previous call to it returns a result. I want to cancel the first call, and only process the result from the last call to HTTPService.send()

I hope this makes sense.

How can I do that??

Thanks!!

+2  A: 

HTTPService has a cancel method. If you call it without its parameter, it should cancel the last invocation of the service. Give that a try and see if you're still getting undesired ResultEvents.

Use the existence of the ASyncToken to determine whether cancellation is appropriate.

private var _serviceCall:ASyncToken;

function callMyService(stuff:Object):void {
    if (_serviceCall !== null) {
        myService.cancel();
        _serviceCall = null;
    }
    _serviceCall = myService.send(stuff)
}
Eric Kolb
+1 because I couldn't accept both answers :)
John Isaacks
+1 from me too because it's a good answer :)
Robert Bak
+3  A: 

Actually HTTPService can manage this for you. It has a concurrency property, which you should probably set to "last".

More info here: HTTPService#concurrency

Robert Bak
A: 

Is there a way to cancel all requests while using multiple calls?

zvjerka24