Reputation:
I have a function (FunctionA) that is being called by another function (FunctionB). The problem is, I'm not sure which function "FunctionB" is.
I have this snippet of code:
function FunctionA():void {
trace("This function was called by " + ???);
}
I need to figure out what to put for "???" so FunctionA's trace statement looks like this:
This function was called by FunctionB
What should I put for "???"?
Upvotes: 0
Views: 1538
Reputation: 120480
I don't think stack trace is available in AS2.
For each possible call site, add the line
arguments.callee.__caller="somestr";
where somestr is unique.
In function A
trace(arguments.caller.__caller);
In response to comment:
I guess theoretically, you could walk the _global object recursively looking for functions and tagging them.
I'm assuming that you aren't using the Flash IDE? This has a debugger (fairly slow and bad), but it should give you a stack trace (if memory serves me right)
Upvotes: 0
Reputation: 10327
An idea that comes to mind is looking at the current stack trace. The entry before the currently executing method should be the routine that called in to FunctionA.
(This is for ActionScript 3.0 but I'm pretty sure it should be available in previous versions)
Upvotes: 1