Archive for November, 2010|Monthly archive page

AS3 Debugging Help – My New Friend – getStackTrace()

This week, for my sins, I have been integrating a Flip Book component into a site I have built using the awesome Gaia Framework. Together, these two code libraries constitute tens of thousands of lines of code and I was getting some run-time errors that I found incredibly difficult to solve. The error text being thrown in the output window revealed next to nothing about where the errors were occurring. Much googling later, I came across a debugging trick that has, until now, passed me by. Basically, you can throw a stack trace in the Debug player at runtime to see exactly where code at that point is originating/firing from. Doing this helped me to instantly locate the source of my troubles. Here is the code:-

//creating but not throwing the error
var er:Error =new Error("BREAK");
// see where issue is happening, but continue running
trace("getStackTrace(): "+er.getStackTrace());

I found this useful trick here – http://troyworks.com/blog/2010/03/14/debug-actionscript-better-with-getstacktrace-trace-trick/ – much thanks to Troy Gardner.