有没有办法在Actionscript 3的编译期间从配置文件中设置private static const
标识符的值?
另外,如果我能在mxmlc ANT任务中执行此操作,那就太好了。
答案 0 :(得分:1)
自己找到解决方案 - 条件编译
http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_21.html
这就是你在actionscript中所做的 -
private static const CONST_PARAM:String = CONFIG::CONST_VALUE;
您的mxmlc命令/任务需要使用-define
选项定义参数。
答案 1 :(得分:1)
对于ANT预编译,您可以放入目标元素:
<replaceregexp
file="yourFile.as"
match="private static const CONST_PARAM:String = '.*';"
replace="private static const CONST_PARAM:String = 'Your new const value';">
</replaceregexp>
如果您希望每次编译时都有一个唯一的构建时间,这将非常有用。在你的ANT预编译中:
<tstamp>
<format property="timestamp" pattern="MM/dd/yyyy hh:mm:ss" />
</tstamp>
<replaceregexp
file="../src/Main.as"
match="private const BUILD_TIME:String = '.*';"
replace="private const BUILD_TIME:String = '${timestamp}';">
</replaceregexp>
然后在你的Main.as课程中:
package Main{
import flash.display.Sprite;
public class Main extends Sprite{
private const BUILD_TIME:String = 'dummy value';
public function Main() {
trace("\n Main.as build-time:" + BUILD_TIME);
}
}
}
它有助于解决swf表现异常的常见问题,因为它未在登台服务器上更新。