Yes, but it can also cause a lot of trouble when used. I have had causes where
the event listener got deleted too early and then you spend a lot of time
finding the issue. And that was not with the Loader-class and Event.COMPLETE or
others.
___
So what would be wrong with always using strong references and always
deleting them when you're done? That's what I do - I feel like I have
more control over what's going on in my code that way. Sure, if I
forget to remove it, it could still be out there, but if you get in the
habit of always
Yep I'm with you – it definitely makes sense to have it default to
false...would lead to a lot of unexpected behaviour especially for beginners if
it defaulted to true.
Piers
On 8 Feb 2010, at 14:41, Merrill, Jason wrote:
So what would be wrong with always using strong references and always
Steven Sacks wrote:
Guess what never fires? If you guessed onComplete, you win the prize.
You do realize that this is not guaranteed, right? It might not fire,
but it may also do fire.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
Could you give an example of the way you use the strong listener?
TIA
-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Steven Sacks
Sent: zondag 7 februari 2010 4:32
To: Flash Coders List
Subject: Re:
Yes, I am doing the same because the trouble weak event listeners can
cause.
function loadImage():void
{
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onComplete, false, 0,
true);
loader.load(new URLRequest(url));
}
function
function onComplete(event:Event):void
{
event.target.removeEventListener(Event.COMPLETE, onComplete);
}
Easy peasy.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
I use a strong listener only when I know I'm not holding a reference to the
dispatcher anywhere else. In all other cases, i.e. if I know I'm going to be
keeping the dispatcher on the display list (if it's a DisplayObject) until I no
longer need it, or if I know I'm storing a reference the
Oooh, OK, it is also the way I do it.
I didn't understand the difference between strong and weakly.
Not my native language, I am Dutch.
Thanks for clearing it to me!
-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com]
Piers Cowburn skrev:
That way, if I forget to remove the event listener in a destroy method or
whatever, it should still end up eligible for GC.
Cases where the event doesn't fire because a weak reference was used only
happen if there are no strong references anywhere else, so the object
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,
11 matches
Mail list logo