There was a brief thread on flexcoders recently about how to check if an swf was built for debugging or for release. With this check you can build all sorts of debugging diagnostics into your application and then compile an unaffected release build without changing any code.
There is no built in way to perform this check, so putting it modestly, the solution is a bit of a hack. In a debug swf, the stack trace contains line number information that is absent in a release swf. To check if you’re in debug mode, all you have to do is throw an error, catch it, and check the stack trace for the square brackets that surround the line numbers.
Here is a little class I wrote that will perform this check.
package com.michaelvandaniker.capabilities { public class SWFCapabilities { private static var hasDeterminedDebugStatus:Boolean = false; public static function get isDebug():Boolean { if(!hasDeterminedDebugStatus) { try { throw new Error(); } catch(e:Error) { var stackTrace:String = e.getStackTrace(); _isDebug = stackTrace != null && stackTrace.indexOf("[") != -1; hasDeterminedDebugStatus = true; return _isDebug; } } return _isDebug; } private static var _isDebug:Boolean; } }
I’ve tested this class in the debug and release versions of Flash Player 10.0.12 and 9.0.124.