Your code looks like this:

function save(xml:XML, successFunc:Function, failureFunc:Function):void {
    var service:HTTPService = new HTTPService();
    ...
    service.addEventListener(ResultEvent.RESULT, function(evt:ResultEvent):void 
{
        trace("Successfully saved XML");
        successFunc();
    });
    service.send(); // called after the event listeners have been added :)
}

That seems unsafe to me.  You are relying on the Player's network stack to keep 
the HTTPService and your result event handlers around.  I've seen other types 
of loads cause the loading class to GC before the result event gets handled.

I would add more code to keep a hard reference to the HTTPService that gets 
cleaned up by the event handlers, although I think there might be advantages to 
keeping a  single HTTPService for multiple requests to the same server, in case 
that's your setup.

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf 
Of Mark Carter
Sent: Friday, December 12, 2008 11:39 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Best practice for calling asynchronous functions?



Alex Harui wrote:
>
> Can you repost your example?
>

Its just the very few simple lines I posted a few posts ago in this topic.
Here is the link:

http://www.nabble.com/Re%3A-Best-practice-for-calling-asynchronous-functions--p20969533.html

Its not a full example, but it gives the idea...
--
View this message in context: 
http://www.nabble.com/Best-practice-for-calling-asynchronous-functions--tp20930596p20988099.html
Sent from the FlexCoders mailing list archive at Nabble.com.

Reply via email to