Specializing in search engine obfuscation

Flash AS3: How to get useful error statements from Flash

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.

Previous

Why HTML5 is not going to kill Flash anytime soon.

Next

Flash AS3: The simple way to create an API reference with ASDoc

6 Comments

  1. Cor

    VERY NICE!!!
    Thank you!

    Here is a very good debugger, which even allows you to edit variables at runtime:
    http://demonsterdebugger.com/

    There is also a tutorial.
    Regards,
    Cor

  2. Beef Johnson

    Holy christ, you’ve been programming flash for 5 years with debugging turned off?!!!

  3. admin

    Sad, but true. I’m completely self-taught, so I end up with weird holes in my knowledge sometimes. This was one of those holes.

  4. I’ve been using Flash since version 4 and never used that checkbox. Thanks for letting me know that’s what it does.

  5. koblongata

    omg, i have that exact knowledge hole for many years! finally.. and thank you, only if i knew it earlier it could have saved me a year of my life time debugging null references!

  6. flashIsBest

    instead of permit debugging you can ctrl+shift+enter and it still will show you where the error is.

Powered by WordPress & Theme by Anders Norén