Alex Rivera | Logout

can an actionscript function find out its own name?

Asked 2009-04-02T20:09:22.893
12

given the following

function A(b:Function)   { }

If function A(), can we determine the name of the function being passed in as parameter 'b' ? Does the answer differ for AS2 and AS3 ?

Edit
Report

2 Answers

2

The name? No, you can't. What you can do however is test the reference. Something like this:

function foo()
{
}

function bar()
{
}

function a(b : Function)
{
   if( b == foo )
   {
       // b is the foo function.
   }
   else
   if( b == bar )
   {
       // b is the bar function.
   }
}
answered 2009-04-02T22:10:49.700
0

Are you merely looking for a reference so that you may call the function again after? If so, try setting the function to a variable as a reference. var lastFunction:Function;

var func:Function = function test():void
{
    trace('func has ran');
}

function A(pFunc):void
{
    pFunc();
    lastFunction = pFunc;
}
A(func);

Now if you need to reference the last function ran, you can do so merely through calling lastFunction.

I am not sure exactly what you are trying to do, but perhaps this can help.

answered 2009-04-03T01:09:54.683

Your Answer