Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 是否可以在编译时从配置文件中设置常量值?_Actionscript 3_Variables_Constants - Fatal编程技术网

Actionscript 3 是否可以在编译时从配置文件中设置常量值?

Actionscript 3 是否可以在编译时从配置文件中设置常量值?,actionscript-3,variables,constants,Actionscript 3,Variables,Constants,在Actionscript 3的编译期间,有没有办法从配置文件中设置私有静态常量的值 另外,如果我能在mxmlc ANT任务中做到这一点,那就太好了。我自己找到了一个解决方案-条件编译 这就是你在actionscript中所做的- private static const CONST_PARAM:String = CONFIG::CONST_VALUE; 您的mxmlc命令/任务需要使用-define选项定义参数。对于ANT预编译,您可以将以下内容放入目标元素中: <replacere

在Actionscript 3的编译期间,有没有办法从配置文件中设置
私有静态常量的值


另外,如果我能在mxmlc ANT任务中做到这一点,那就太好了。

我自己找到了一个解决方案-条件编译

这就是你在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>
它有助于解决一个常见问题,即您的swf由于未在临时服务器上更新而出现意外行为

<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>
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);
        }
    }
}