You can't pass a reference to a method call like you seem to be trying to do by 
'bar.doLast'. You *can* pass functions around, but not object methods -- they 
no longer know what object they are supposed to act on.

See:

var a:Array = [1, 2, 3];
a.shift(); // a = [2, 3];
var shiftMethod:Function = a.shift;
shiftMethod(); // a still equals [2, 3] - this did nothing

One solution would be something like this:

public function doFirst(aString:String, aBarInstance:Bar, 
aBarMethodName:String) {
     trace("the first string is "+aString);
 
     aBar["aBarMethodName"]();
}

This is pretty nasty, though. You should probably let us know what the effect 
you are going for is so someone can suggest a better way, probably involving 
either untangling these two objects or using mx.utils.Delegate.

-mark hawley
> 
> From: "Elie Zananiri" <[EMAIL PROTECTED]>
> Date: 2006/06/29 Thu PM 02:21:47 CDT
> To: [email protected]
> Subject: [Flashcoders] trying to call a function passed as an argument
> 
> Hi all,
> 
> I have this method where I need to call a function passed as an argument
> (kind of like in setInterval()) and I don't understand the documentation and
> can't get it to work.
> 
> First of all, I don't understand how to pass the function as a parameter.
> Am I passing a String or an actual Function object?  Can I pass a Function
> with parameters?  Do I have to write the parentheses in the parameter?
> 
> Next, how do I call this function?  The Function.call() function requires a
> parameter but I don't get what it does...
> 
> Thanks for the help!
> 
> -Elie
> 
> Here is the structure I have:
> 
> class Bar {
>   public Bar() {
>   }
> 
>   public function doLast(bString:String) {
>     trace("the second string is "+bString);
>   }
> }
> 
> class Foo {
>   var bar:Bar;
> 
>   public Foo() {
>     bar = new Bar();
>     doFirst("hello", "world", bar.doLast);
>   }
> 
>   public function doFirst(aString:String, bString:String,
> aFunction:Function) {
>     trace("the first string is "+aString);
> 
>     // call the second function here ???
>     aFunction.call(??);
>   }
> }
> _______________________________________________
> [email protected]
> 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
> 

--
John Mark Hawley
The Nilbog Group
773.968.4980 (cell)

_______________________________________________
[email protected]
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