J - you're totally right - i just avoid relying on the caller bit overall
as its not as flexible( for how i code ) :)


>>>"You often see people use delegates this way as well:
> buttonComponent.addEventListener("click",Delegate.create
> (this,onButtonClick));
>
> This is handy- but if you have to remove that listener at a point in
> time, you have no reference to it in order to remove it, so clean up
> becomes hard. I usually create a variable to hold the reference and pass
> it in: public var delegateItem:Function;"
>
> not true.
>
> you can use arguments.caller to remove the listener when adding it like
> that. obviously that is only doable in the handler function.
>
> On 4/12/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>>
>> My two cents -
>>
>> EventDispatcher you use as a mixin, which basically means its a class
>> you don't use solely on its own, and its purpose is to dynamically add
>> something to object you mix it into. The members or functions of that
>> mixin class basically get added to your class (to the prototype object
>> - someone feel free to correct me if I am wrong - this is my
>> understanding). EventDispatcher affords you 3 primary functions you
>> use -
>> addEventListener,removeEventListener and dispatchEvent. Mixing in a
>> class is an effective way to get additional functionality without
>> inheriting - as AS doesn't support multiple inheritance.
>>
>> With EventDispatcher you can mix it in- in a couple of ways. You can
>> initialize the class itself to be a broadcaster
>> (EventDispatcher.initialize(this)), you can utilie composition and
>> have an object which will then be the event source ( like adding an
>> object in your class that takes care of all the broadcasting
>> responsibilities) and there's another way I havent' seen implemented
>> too often where you pass the class protoype - in fact the first time I
>> saw this approach was on darron schall's blog
>> (http://www.darronschall.com/weblog/archives/000100.cfm).
>>
>> Delegate is a class that basically delegates/proxies the call. IN the
>> past, to do somethign like load in xml and then call a function in the
>> class, you would often see people do something like:
>>
>> myXML=new XML());
>> myXML.host=this;// or myXML["host"]=this;
>> myXML.onLoad=function(){
>>    this.host.parseLoadedXML();
>> }
>> myXML.load("file.xml");
>>
>> WITH Delegate it takes care of making sure items are called in the
>> scope you designate, taking the scope/object and the function it
>> should fire. myXML=new XML());
>> myXML.onLoad=Delegate.create(this,parseLoadedXML);
>> myXML.load("file.xml");
>>
>> Delegate returns you a function. You can retain a reference to that
>> function by going somethign like:
>> var d:Function=Delegate.create(this,onHandleMethod);
>>
>> You often see people use delegates this way as well:
>> buttonComponent.addEventListener("click",Delegate.create
>> (this,onButtonClick));
>>
>> This is handy- but if you have to remove that listener at a point in
>> time, you have no reference to it in order to remove it, so clean up
>> becomes hard. I usually create a variable to hold the reference and
>> pass it in: public var delegateItem:Function;
>>
>> delegateItem=Delegate.create(this,onButtonClick);
>> buttonComponent.addEventListener("click",delegateItem);
>>
>>
>> THen when i have to remove:
>> buttonComponent.removeEventListener("click",delegateItem);
>>
>>
>> I guess I am feeling verbose tonight. Anyone, jump in and correct me
>> where I might and possibly be wrong :)
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> 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
>>
>
>
>
> --
> j:pn
> http://www.lennel.org
> _______________________________________________
> 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



_______________________________________________
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