Another thing to note:

Delegating the event as such:
_dg.addEventListener("change", Delegate.create(this,
datagridChangeHandler));

will NOT allow you to remove the event listener.

This won't work:
_dg.removeEventListener("change", Delegate.create(this,
datagridChangeHandler));


What I usually do is have a private variable:

private var datagridChangeHandler_func

and then create the delegate:

datagridChangeHandler_func = Delegate.create(this, datagridChangeHandler);

Thany you would add and remove it as:

_dg.addEventListener("change", datagridChangeHandler_func);

_dg.removeEventListener("change", datagridChangeHandler_func);

- James

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Muzak
Sent: Thursday, June 07, 2007 12:22 PM
To: flashcoders@chattyfig.figleaf.com
Subject: Re: [Flashcoders] EventDispatcher weirdness in AS2


Even though it's possible to use the class instance as the listener (this),
you're still better off using Delegate.
What if you have 2 instances dispatching the same event that need to be
handled completely different?

submit_btn.addEventListener("click", this);
aTotallyUnrelated_btn.addEventListener("click", this);

The above will work, but they'll both trigger the same event handler and
you'll have to resort to if()else() stuff.
No big deal if you have 2 buttons.. get's hairy with loads of buttons.
Or what about different components (DataGrid, ComboBox, List, etc..) who all
dispatch a "change" event..

_dg.addEventListener("change", this);
_cb.addEventListener("change", this);
_list.addEventListener("change", this);

versus:

_dg.addEventListener("change", Delegate.create(this,
datagridChangeHandler));
_cb.addEventListener("change", Delegate.create(this, comboChangeHandler));
_list.addEventListener("change", Delegate.create(this, listChangeHandler));

Get in the habit of using Delegate (in AS2) and *always* use it.. no
exceptions ;-)

regards,
Muzak

----- Original Message -----
From: "Alain Rousseau" <[EMAIL PROTECTED]>
To: <flashcoders@chattyfig.figleaf.com>
Sent: Thursday, June 07, 2007 4:07 PM
Subject: RE: [Flashcoders] EventDispatcher weirdness in AS2


> Hehe no prob.
>
> For your listener are you doing something like
>
> _myClass.addEventListener("onTransition", Delegeate.create(this,
> onTransitionHandler));
>
> private function onTransitionHandler() {
> //do stuff
> }
>
> don't you prefer
>
> _myClass.addEventListener("onTransition", this);
>
> function onTransition() {
> //do stuff
> }
>
> for better clarity and less code writing ? No need of delegate in this
case.
>
> Of course it's a question of choice and habit. Just to let you know of the
> alternatives !
>
> Alain
>


_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.472 / Virus Database: 269.8.7/830 - Release Date: 6/3/2007
12:47 PM

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.472 / Virus Database: 269.8.7/830 - Release Date: 6/3/2007
12:47 PM

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to