Could you give an example of the way you use the strong listener?

TIA

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Steven Sacks
Sent: zondag 7 februari 2010 4:32
To: Flash Coders List
Subject: Re: [Flashcoders] Re: is it ever ideal to NOT use weak references?

function loadImage():void
{
     var loader:URLLoader = new URLLoader();
     loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
     loader.load(new URLRequest(url));
}
function onComplete(event:Event):void
{
     trace(event);
}

Guess what never fires?  If you guessed "onComplete", you win the prize.

Now imagine that it defaulted to true and you wrote the same thing leaving
off 
the false, 0, true.  You would have no idea why it didn't work.

It didn't work because the loader was cleaned up by GC as soon as the 
loadImage() function reached the end.

Generally, I only use weak listeners with Timers and enter frame listeners. 
Everything else I use strong listeners and write a remove listener for them
when 
they're expected to unload or be garbage collected at some point.
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 9.0.733 / Virus Database: 271.1.1/2673 - Release Date: 02/07/10
08:22:00

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to