[ActionScript&Flex] FlashBuilder编译条件之如何屏蔽调试代码

下面讲一下在FlashBuilder中如何添加编译器参数使我们在发布的时候不编译调试代码:

首先设置编译参数

编译参数设置好后,代码我们可以这样写:

public class ConditionalCompilationTest extends Sprite
{
      public function ConditionalCompilationTest()
      {
            CONFIG::DEBUG
            {
                  var sp:Sprite = new Sprite();
                  sp.graphics.beginFill(0xff0000);
                  sp.graphics.drawRect(0,0,100,100);
                  sp.graphics.endFill();
                  addChild(sp);
                  trace("编译条件测试");
            }
      }
}


将编译参数 -define=CONFIG:DEBUG,true中true改为false,调试一下,我们发现CONFIG::DEBUG里面的代码没有执行,等发布项目的时候将这里改为false就可以屏蔽掉这些不需要编译的代码了。

原文地址:https://www.cnblogs.com/frost-yen/p/5302511.html