0

In actionscript3, i have a function variable that is assigned to one of 100 functions.

During execution, i want to be able print out the name of the function it assigned to. Unfortunately if you say trace (f) where f is function variable, it merely reports the parameter types and return value type of the function, doesn't mention its name, even if the function is static. Anyone know a trick to get the string representation of the function variable? Too bad Adobe didn't think of this issue, it is a helpful thing when debugging.

Edward De Jong
  • 151
  • 1
  • 9
  • Strikes me as an unusual use case, rarely practical for debugging. Use `describeType()` or throw an error and examine the stack trace, such as [here](http://stackoverflow.com/questions/711404/can-an-actionscript-function-find-out-its-own-name). Neither should be used in production code. – Jason Sturges Apr 29 '15 at 06:46
  • Please post 2 or more of these functions. It would be very helpful to know what these functions are doing. – null Apr 29 '15 at 07:38

2 Answers2

1

Short answer: You can't. References to functions do not have names in Actionscript.

Long answer: It's possible if you know the class that defined the function and the function is public. You can iterate over the methods of the class until you find one that matches the reference you have, and then you know the name. See this stackoverflow answer

Community
  • 1
  • 1
takteek
  • 7,020
  • 2
  • 39
  • 70
  • In my case i just have a few hundred static functions in misc. classes, and i have so many function variables that i wanted to do some tracing on them. Unfortunately there is no way to convert a function variable to a string, so one would have to build a array/dictionary of all possible function variables, and store into that table the string form of the function variable. Clearly AS knows at run time the absolute address of the function, and given that it can report such errors in the debugger clearly has the info it needs to do this, they just didn't bother to implement this feature – Edward De Jong May 03 '15 at 03:41
0

I ended up creating a new object type, that is a wrapper around a function pointer, that has an additional field containing the name of the function, so that way i can debug what a function pointer points to at runtime. A brute force method, but it works.

Edward De Jong
  • 151
  • 1
  • 9