开发者

Is it possible to set constant value from a config file during compile time?

Is there a way to set the value of a private static const identifier from a config file during compile time in Actionscript 3?

Also, it would 开发者_JS百科be nice if I can do this in the mxmlc ANT task.


Found a solution myself - Conditional Compilation

http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_21.html

This is what you do in actionscript -

private static const CONST_PARAM:String = CONFIG::CONST_VALUE;

And your mxmlc command/task needs to define the parameter using the -define option.


For an ANT pre-compile you can put inside your target element:

<replaceregexp 
   file="yourFile.as" 
   match="private static const CONST_PARAM:String = '.*';" 
   replace="private static const CONST_PARAM:String = 'Your new const value';">
</replaceregexp>

This is especially useful if you want a unique build time each time you compile. In your ANT pre-compile:

<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>

Then in your Main.as class:

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

It helps to troubleshoot the common issue that your swf is behaving unexpectedly because it wasn't updated on the staging server.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜