确定swf是否处于“调试”播放器或模式 [英] Determine if swf is in a "debug" player or mode

查看:288
本文介绍了确定swf是否处于“调试”播放器或模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a way using Flash (CS3+AS3) to determine if the published swf is running in a debug player or in Flash's debug mode?

我是意识到Flex提供了设置不同的构建目标(释放/调试)的功能,您可以使用 CONFIG :: debug #ifdef 在编译时包含代码的样式。

I'm aware that Flex provides the ability to setup different build targets (release/debug) and that you can use something like CONFIG::debug for #ifdef style inclusion of code at compile time.

我想象的是像$ code> System.isDebug()但找不到任何东西。我想使用这个,因为我的应用程序中有调试功能,我确定不希望在生产环境中可用。

I'm imagining something like System.isDebug() but can't find anything. I want to use this because there's debug functionality in my app that I definitely don't want to be available in a production environment.

推荐答案

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

这个类提供了两个相关的(和不同的)信息:

This class provides two pertinent (and different) pieces of information:


  • SWF是否使用-debug开关构建(已调试符号)?

  • Flash Player是否为调试播放器(有能力显示错误等)?

Capabilities.isDebugger只回答第二个问题 - 用户是否正在运行Flash调试播放器。在您的情况下,要在调试版本上部署应用程序,您需要--debug构建检查(然后不要将-debug版本生成)生产。

The Capabilities.isDebugger only answers the second question - is the user running the Flash Debug player. In your case, to gate portions of your application on a debug build, you want the -debug build check (and then don't deliver -debug builds into production).

但请注意,这两个检查都是运行时检查。在调试代码周围使用条件编译(又称CONFIG :: debug)仍然是一个好主意,因为它将确保可能敏感的调试代码不会在最终的SWF中提供,使其尽可能小且安全。

Note however, that both these checks are runtime checks. Using conditional compilation (aka CONFIG::debug) around your debug code is still a good idea, as it will ensure that possibly sensitive debug code is NOT delivered in the final SWF, making it as small and secure as possible.

我在这里复制引用的代码,以防博客链接发生故障:

I'm reproducing the referenced code here, in case the blog link ever goes down:

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

这篇关于确定swf是否处于“调试”播放器或模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆