It's not possible in general, having only reference to the function (as mentioned in this accepted answer Actionscript - Obtain the name of the current function). There is only two ways to get the name:
using
describeType
, but in this case you have to provide the function host object. You can find example in the first answer Actionscript - Obtain the name of the current function, I modified it for the static functions as well and utilizinggetSavedThis
that works in the debug player only:var name:String = getFunctionName( staticTest ); trace("1", name); name = getFunctionName( staticTest, Astest ); //Astest the name of the class that hosts staticTest function trace("2", name); public static function staticTest():void { } public static function getFunctionName( func:Function, parent:* = null ):String { if(!parent) { //works only in debug flash player parent = getSavedThis(staticTest); } var methods:XMLList = describeType(parent)..method; for each ( var m:XML in methods) { if (parent[m.@name] == func) return m.@name; } return null; }
output:
[trace] 1 staticTest
[trace] 2 staticTest
- using getStackTrace (example in the same answer) but it works only in debug player and you have to be in the function closure.