在开发过程,由于代码调试的需要,会使用很多trace来输出信息或者其他测试函数,所以在发布时屏蔽这些代码会比较麻烦。而FB允许自定义宏,可以轻易地解决此问题。
1、添加自定义宏
宏定义的有固定的格式: -define=namespace::variable_name,value
2、获取宏的值
trace(CONFIG::debug); ——–output:true
trace(CONFIG::release ); ——–output:false
3、使用宏
public class Test extends Sprite
{
public function Test()
{
init();
}
CONFIG::debug{
private function init():void
{
trace('debug init');
}
}
CONFIG::release{
private function init():void
{
trace('release init');
}
}
}
//当设置-define=CONFIG::debug,true
———output:debug init
//当设置-define=CONFIG::release,true
———output:release init
ps:当-define=CONFIG::debug,true和-define=CONFIG::release,true时,使用时冲突;当都设为false时,不起作用。