How to identify at runtime if the swf is in debug or release mode/build
It may be interesting to know at runtime whether an application is running from a debug or release SWF file. It allows the application to automatically execute debug specific code when the file is a debug SWF file and ignore this code when it is published as a release file. Also, it should be nice to know if you have a debug flash player just for the same reasons. But for the last one, there is a function in the Capabilities class called isDebugger.
One solution would be to use conditional compilation. The other solution is in the following code (hack).
package org.adm.runtime { import flash.system.Capabilities; public class ModeCheck { /** * Returns true if the user is running the app on a Debug Flash Player. * Uses the Capabilities class **/ public static function isDebugPlayer() : Boolean { return Capabilities.isDebugger; } /** * Returns true if the swf is built in debug mode **/ public static function isDebugBuild() : Boolean { var st:String = new Error().getStackTrace(); return (st && st.search(/:[0-9]+]$/m) > -1); } /** * Returns true if the swf is built in release mode **/ public static function isReleaseBuild() : Boolean { return !isDebugBuild(); } } } |
This code simply searches for line numbers of errors in StackTrace result. Only StackTrace result of a debug SWF file contains line numbers. Then we know that we are running a debug or release SWF file.
This class is also available in the Components Pack at Runtime subpackage