Do you really need the call bit >? Can you not just do something like:

var host=this;
mc.onRelease=function(){
 host.fireFunction();
}
function fireFunction(){
trace("function called")
}


You can use delegates for more than just components - I use delegate most
often when I want an item/class to have a public no-op function that I can
overwrite outside of it - like a layoutclass that draws items to the
stage, i might want to overwrite what it does when its finished laying
stuff out- a totally made up example might be :



var LM:LayoutManager=new LayoutManager();
LM.onLayoutComplete=Delegate.create(this,layoutChildren);
LM.doLayout("grid",items);

function layoutChildren():Void{
 trace(" layout is done");
}

Alot of people complain that you can't pass parameters with delegate. Well
you can, a multiple of ways, and if you structure your code with some
forethought, you can have it pass params if you are delegating a function
structured do so. I would argue that if its not flexible enough for you ,
then maybe you need to revisit your architecure and determine if Delegate
is  what you need or if you're really in need of using something else such
athe dispatch scenerio.  One thing to remember is that Delegate is just a
function, and therefore you can add properties to it and have a reference
to it. I don't know how proper that is, but it works.

var myDelegate:Function =mx.utils.Delegate.create(this,onComplete);
myDelegate.someProperty="foo";

myButton.addEventListener("click",myDelegate);

function onComplete(obj:Object):Void{
  trace(arguments.caller.someProperty)
}




> While not as elegant, you can get around this issue delegate-free with
> the following:
>
> class SomeClass {
>
>       private var a:Number = 3;
>
>       function SomeClass(mc:MovieClip){
>
>               var thisObj = this;
>               // Set a reference to "this"
>
>               mc.onRelease = function(){
>
>                       thisObj.onRelease.call(thisObj);
>               }
>
>       }
>
>       function onRelease(){
>
>               trace("this.a: "+this.a);
>
>       }
> }
>
> --
>
> Joseph
>
> James Marsden wrote:
>> The delegate class is a godsend for so many things...
>>
>>
>> // inside a class:
>>
>> mc.onEnterFrame = mx.utils.Delegate.create(this, main);
>>
>> function main()
>> {
>>    // the mc is calling my method, and I can access all my properties
>> as
>> if I was calling it myself
>> }
>>
>>
>>
>>
>> Stephen Ford wrote:
>>
>>> Hello All,
>>>
>>> Can anyone confirm that the Delegate class is only helpful when using
>>>  components ?
>>>
>>> Or should it also be used for events outside the component framework
>>> ?
>>>
>>> No doubt it depends on what your trying to achieve, but just
>>> generally  speaking, what do you think.
>>>
>>> Thanks,
>>> Stephen.
>>>
>>>
>> _______________________________________________
>> 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



_______________________________________________
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