First of all, I'm NOT talking about if the player is a debugger or not. (EDIT: it IS actually related to the debugger player)
I use mxmlc
to compile a very simple swf file with -debug=false
:
mac-108:tmp admin$ "/Applications/Adobe Flash Builder 4.7/sdks/4.6.0/bin/mxmlc" +configname flex -debug=true -static-link-runtime-shared-libraries=true Main.as
Loading configuration file /Applications/Adobe Flash Builder 4.7/sdks/4.6.0/frameworks/flex-config.xml
/Users/admin/tmp/Main.swf (987 bytes)
mac-108:tmp admin$
The Main.as
:
package {
import flash.display.MovieClip;
import flash.text.*;
public class Main extends MovieClip {
public function Main() {
// Reference: http://stackoverflow.com/questions/185477/determine-if-swf-is-in-a-debug-player-or-mode
var st:String = new Error().getStackTrace();
var isDebugBuild:Boolean = (st && st.search(/:[0-9]+]$/m) > -1);
var my_st:String = "st: " + (st == null ? 'Null' : st);
var my_DR:String = isDebugBuild?"Debug":"Release";
var obj:TextField = new TextField();
obj.text = my_st + "\n" + my_DR;
this.addChild(obj);
}
}
}
Then I open Main.swf
in my Chrome browser, but I see:
st:Null
Release
Which is so weird that, apparently, I have set -debug=true
, why does NOT the popular method to determine if an swf is in Debug or Release work.
However, if I move my code to the Flash Builder 4.7, it will give me the Debug
output (instead of Release
).
It turns out that when the SWF is built in Debug mode, in order to test if it's in debug mode, the Flash Player must also be a debugger using Capabilities.isDebugger
.