如何以编程方式告诉Flex App是否在调试模式下运行?

Mid*_*Gun 5 apache-flex debugging flash actionscript-3

是否可以在Flex应用程序中编写代码,该代码只能在调试版本中运行,或者在调试器中运行时?Flex是否提供了一种从发布版本中完全删除代码的方法,比如C风格的#defines?

该应用不一定在网页中运行.

The*_*heo 10

您可以像这样进行条件编译:

CONFIG::debugging {
    // this will be removed if CONFIG::debugging resolves to false at compile time
}
Run Code Online (Sandbox Code Playgroud)

然后将其添加到编译器标志:

-define+=CONFIG::debugging,true
Run Code Online (Sandbox Code Playgroud)

用于调试版本,以及

-define+=CONFIG::debugging,false
Run Code Online (Sandbox Code Playgroud)

发布版本.CONFIG并且debugging可以是任何东西,比如MY_AWESOME_NAMESPACEfooBar,并不重要.

在此处阅读更多内容:使用条件编译.