Flex:是否可以保证在无法访问时从编译的构建中排除代码?

时间:2009-11-11 18:12:34

标签: flex actionscript-3 actionscript flex3

假设你有

private static const INCLUDE_MY_DEBUG_CODE:Boolean = false;

public function runMyDebugCode():void
{
    if ( INCLUDE_MY_DEBUG_CODE )
    {
        callADebugFunction();
    }
}

private function callADebugFunction():void
{
    ...
}

鉴于没有其他对callADebugFunction的引用,是否可以保证callADebugFunction不是编译构建的一部分?

2 个答案:

答案 0 :(得分:8)

如果没有对文件/类的引用 - 那么它就不会被编译。

在您的情况下,如果您从外部引用此类 - 将编译所有方法。

使用compilation variables从发布中删除调试代码。

转到Project-> Properties-> Flex Compiler并添加

对于调试模式:

-define=CONFIG::release,false -define=CONFIG::debugging,true

或发布:

-define=CONFIG::release,true -define=CONFIG::debugging,false

然后在你的函数runMyDebugCode()

CONFIG::debugging { 
    trace("this code will be compiled only when release=false and debugging=true");
}


CONFIG::release { 
    trace("this code will be compiled only when release=true and debugging=false");
}

答案 1 :(得分:0)

我非常怀疑。由于某些东西正在引用该函数(无论是否在运行时到达),因此该代码很可能实际上被编译到您的SWF / SWC文件中。

有更好的方法可以防止调试代码在发布版本中结束。请参阅zdmytriv的回答。