Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StackTrace in Flash / ActionScript 3.0

I want to see the stack trace in any function of my code, so i made somthing like this to call it and print the stack trace:

public function PrintStackTrace() {     try {         throw new Error('StackTrace');     } catch (e:Error) {         trace(e.getStackTrace());     } } 

I like to know if there are other way to do this. In some place, the Error class creates the stack trace, but maybe it didn't do it with ActionScript 3.0 so maybe it's not posible, but i want to know.

Thanks!

like image 548
Lucas Gabriel Sánchez Avatar asked Sep 29 '08 15:09

Lucas Gabriel Sánchez


People also ask

What is error Stacktrace?

Stack trace error is a generic term frequently associated with long error messages. The stack trace information identifies where in the program the error occurs and is helpful to programmers. For users, the long stack track information may not be very useful for troubleshooting web errors.

What is JS Stacktrace?

A stack trace is a list of the functions, in order, that lead to a given point in a software program. A stack trace is essentially a breadcrumb trail for your software. You can easily see the stack trace in JavaScript by adding the following into your code: console.

What is ActionScript code?

ActionScript is the programming language for the Adobe® Flash® Player and Adobe® AIR™ run-time environments. It enables interactivity, data handling, and much more in Flash, Flex, and AIR content and applications. ActionScript executes in the ActionScript Virtual Machine (AVM), which is part of Flash Player and AIR.


2 Answers

As far as I know, the only way to make the stack trace available to your own code is via the getStackTrace() method in the Error class, just like you're already doing. In response to the example in your question, though, I would mention that you don't actually have to throw the Error -- you can just create it and call the method on it:

var tempError:Error = new Error(); var stackTrace:String = tempError.getStackTrace(); 

Also, like the documentation says, this only works in the debug version of Flash Player, so you can wrap this functionality in an if-block that checks the value of Capabilities.isDebugger if you want.

like image 132
hasseg Avatar answered Oct 07 '22 11:10

hasseg


From Flash Player 11.5 the stack traces are also available in the non-debugger versions of the players as well.

like image 33
Glen Blanchard Avatar answered Oct 07 '22 11:10

Glen Blanchard