xiangpei01
Flash/Flex构架师 / 广东
积分 146

判断你的Flex应用是调试还是发布版


2010-07-07 点击:


How to identify at runtime if the swf is in debug or release mode/build

如何识别swf文件是测试版的还是正式发布版的

It may be interesting to know at runtime whether an application is running from a debug or release SWF file. It allows the application to automatically execute debug specific code when the file is a debug SWF file and ignore this code when it is published as a release file. Also, it should be nice to know if you have a debug flash player just for the same reasons. But for the last one, there is a function in the Capabilities class called isDebugger.

One solution would be to use conditional compilation. The other solution is in the following code (hack).
 

  1. package org.adm.runtime  
  2. {  
  3. import flash.system.Capabilities;  
  4.  
  5. public class ModeCheck  
  6. {  
  7.    /**  
  8.    * Returns true if the user is running the app on a Debug Flash Player.  
  9.    * Uses the Capabilities class  
  10.    **/  
  11.    public static function isDebugPlayer() : Boolean  
  12.    {  
  13.     return Capabilities.isDebugger;  
  14.    }  
  15.  
  16.    /**  
  17.    * Returns true if the swf is built in debug mode  
  18.    **/  
  19.    public static function isDebugBuild() : Boolean  
  20.    {  
  21.     return new Error().getStackTrace().search(/:[0-9]+]$/m) > -1;  
  22.    }  
  23.  
  24.    /**  
  25.    * Returns true if the swf is built in release mode  
  26.    **/  
  27.    public static function isReleaseBuild() : Boolean  
  28.    {  
  29.     return !isDebugBuild();  
  30.    }  
  31. }  
  32. }  

This code simply searches for line numbers of errors in StackTrace result. Only StackTrace result of a debug SWF file contains line numbers. Then we know that we are running a debug or release SWF file.

This class is also available in the Components Pack at Runtime subpackage


    xiangpei01  版权所有
    禁止任何用途(禁止转载、商用和个人使用)


所属分类:技术经验分享

本文标签:Flex应

各位正在潜水的同学请注意,有0位无聊人士 在EBIBI附近出没!







    点击我更换图片 看不清
    评论内容 (*必填):

    (Ctrl + Enter 快速提交)