One of my main frustrations with Flash is the lack of useful error statements when I am testing a program. The compiler errors are okay – they catch my syntax mistakes and point out the location of the problem in my code (usually). Runtime errors , on the other hand, are an exercise in frustration. Flash usually provides cryptic runtime errors like “null object reference” and then gives me a vague hint about where the problem is in my code. Then, I spend lots of time adding trace statements to try to figure out where the code is failing. Once I know where the code fails, I can figure out why. I have constantly wondered why Flash can’t simply give me the exact location where the program crashed.

Flash runtime error

Well, one of my coworkers figured out how to get useful error statements from Flash the other day and I’m ashamed to admit that I didn’t know this (neither did he, and we’ve both been developing in Flash for over 5 years). In Flash CS3 or higher, simply open the Publish Settings and go to the Flash tab. One of the checkboxes on this tab says “Permit Debugging.” Enable this and Flash will tell you exactly where your program failed, so you can quickly track down why it happened.

As always, I’ve attached a quick example. The sample Flash file has a problem that will cause Flash to throw a runtime error. Compile it and note how it only tells you that the problem is in the actionscript on frame 1 (no duh). Now, change the publish settings to permit debugging and try again. This time, at the end of the error message, it will actually tell you the exact line of code where the program crashed.

Once you are finished testing your applications, you should probably turn debugging off before publishing your final SWF.

Download the sample file here.