有没有办法使用 Flash (CS3+AS3) 来确定发布的 swf 是在调试播放器中运行还是在 Flash 的调试模式下运行?
我知道 Flex 提供了设置不同构建目标(发布/调试)的能力,并且您可以使用类似的东西CONFIG::debug
for #ifdef
编译时代码的样式包含。
我在想象类似的事情System.isDebug()
但找不到任何东西。我想使用它,因为我的应用程序中有调试功能确实不想在生产环境中可用。
看看这个类http://blog.another-d-mention.ro/programming/how-to-identify-at-runtime-if-swf-is-in-debug-or-release-mode-build/ http://blog.another-d-mention.ro/programming/how-to-identify-at-runtime-if-swf-is-in-debug-or-release-mode-build/
此类提供了两条相关(且不同)的信息:
- SWF 是否使用 -debug 开关构建(已编译调试符号)?
- Flash 播放器是调试播放器(能够显示错误等)吗?
Capability.isDebugger 仅回答第二个问题 - 是用户运行 Flash 调试播放器。在您的情况下,要在调试构建上控制应用程序的部分,您需要 -debug 构建检查(然后不要将 -debug 构建交付到生产中)。
但请注意,这两项检查都是运行时检查。在调试代码周围使用条件编译(又名 CONFIG::debug)仍然是一个好主意,因为它将确保可能敏感的调试代码不会在最终的 SWF 中传递,从而使其尽可能小且安全。
我在这里复制引用的代码,以防博客链接失效:
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 stackTrace:String = new Error().getStackTrace();
return (stackTrace && stackTrace.search(/:[0-9]+]$/m) > -1);
}
/**
* Returns true if the swf is built in release mode
**/
public static function isReleaseBuild() : Boolean
{
return !isDebugBuild();
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)