【问题标题】:Determine if swf is in a "debug" player or mode确定 swf 是否处于“调试”播放器或模式
【发布时间】:2010-09-16 04:12:21
【问题描述】:

有没有办法使用 Flash (CS3+AS3) 来确定发布的 swf 是在调试播放器中运行还是在 Flash 的调试模式下运行?

我知道 Flex 提供了设置不同构建目标(发布/调试)的能力,并且您可以在编译时使用 CONFIG::debug 之类的 #ifdef 样式包含代码。

我想像System.isDebug() 这样的东西,但找不到任何东西。我想使用它,因为我的应用程序中有调试功能,我绝对不希望在生产环境中可用。

【问题讨论】:

  • 好问题。了解这一点很重要,因为错误会在调试播放器中向用户发出警告,并且可能存在其他差异。
  • @Antti 过时链接?
  • @MattAllegro 是的,那个链接是 10 年前发布的。它是官方文档,但我猜它已经被删除了。

标签: flash actionscript-3 debugging


【解决方案1】:

看看这个课程http://blog.another-d-mention.ro/programming/how-to-identify-at-runtime-if-swf-is-in-debug-or-release-mode-build/

该类提供了两条相关(且不同)的信息:

  • 是否使用 -debug 开关构建 SWF(已编译调试符号)?
  • Flash 播放器是调试播放器(能够显示错误等)吗?

Capabilities.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();
    }
  }
}

【讨论】:

  • 当它是调试播放器时,您的方法isDebugBuild 将始终返回false。我的看法是,当播放器是调试器时,没有办法判断 SWF 是调试版本还是发布版本。
  • @PeterLee 它可以是调试播放器,但不是 swf 的调试版本。调试版本包含堆栈跟踪中的行号信息。
猜你喜欢
  • 1970-01-01
  • 2010-11-09
  • 1970-01-01
  • 1970-01-01
  • 2012-04-03
  • 1970-01-01
  • 2011-05-20
相关资源
最近更新 更多