A rather dirty way is to enumerate all methods in a given object (the
current timeline, for instance) and compare that to the "self-reference"
that a function holds in arguments.callee.


function test():void {
 trace(getName(arguments.callee,this));
}

function getName(funcRef:Function,scope:*):String {
 var funcName:String = "";
 var desc:XML = flash.utils.describeType(this);

 var methodTable:XMLList = desc..method.(@name != "" && @name != null);

 for each (var item:XML in methodTable){
  if([EMAIL PROTECTED] == funcRef) {
   funcName = [EMAIL PROTECTED];
   break;
  }
 }

 return funcName;
}

test();

It's just a quick and dirty test, but it works (at least in the timeline).

Cheers
Juan Pablo Califano


2008/9/16 Jiri Heitlager <[EMAIL PROTECTED]>

> Does somebody now if it is possible to get the name of a function from the
> scope of that function.
>
> function doSomething():void
> {
>        trace('the name of this function is ' , $$name$$)
> }
>
> Where the trace would be :
> the name of this function is doSomething
>
> In Java one has acces to stack traces, does AS3 provide acces to this?
>
> Jiri
>
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to