>That's a dangerous practice.

I do not completely agree.

>It prevents you from using weak event listeners

Correct.

The common use for weak event
listeners is when adding listeners to the stage: the stage is allways
present and adding normal listeners to it will insure that the
listener will persist. Even if it is removed everywhere else.

In most cases there is actually no real benefit of creating weak event
listeners. In most cases parents add
listeners to their children. Children are removed and that's that. If
the parent gets removed: no problem.

In the majority of the cases, the creation of listeners on a parent is bad
practice (stage is one of those exceptions).


> Now have to manually remove your listener to
> make sure your object is garbage collected -- but the only way to
> remove event listeners is to pass the removeEventListener function a
> reference to the function you want to remove... but you don't have
> that reference!

Hmmm, if it was garbage collected, why would I remove the listener, isnt
that the point of weak references?


Greetz Erik


On 3/12/08, Cory Petosky <[EMAIL PROTECTED]> wrote:
>
> That's a dangerous practice. It prevents you from using weak event
> listeners -- because the only reference to your delegate function
> object is the event listener itself, a weakly-referenced listener will
> be garbage collected. Now have to manually remove your listener to
> make sure your object is garbage collected -- but the only way to
> remove event listeners is to pass the removeEventListener function a
> reference to the function you want to remove... but you don't have
> that reference!
>
> If it's a one-time event, you can have the listener remove itself.
> Your delegate function object can pass a reference to itself (using
> arguments.callee) in to the "real" event listener function, which you
> can use to remove the listener. In any other case, you'll have to
> build a separate data structure (usually a Dictionary of Objects ->
> Functions) to keep a reference available to your code.
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to