【发布时间】:2010-11-23 23:38:45
【问题描述】:
有没有办法在 Actionscript 3 的编译期间从配置文件中设置 private static const 标识符的值?
另外,如果我能在 mxmlc ANT 任务中做到这一点,那就太好了。
【问题讨论】:
标签: actionscript-3 variables constants
有没有办法在 Actionscript 3 的编译期间从配置文件中设置 private static const 标识符的值?
另外,如果我能在 mxmlc ANT 任务中做到这一点,那就太好了。
【问题讨论】:
标签: actionscript-3 variables constants
自己找到了解决办法——条件编译
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 选项定义参数。
【讨论】:
对于 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 行为异常的常见问题,因为它没有在暂存服务器上更新。
【讨论】: