在动作脚本中定义

Dec*_*ado 6 apache-flex compilation const actionscript-3

我正在尝试将构建号从Hudson传递到Flex应用程序.

我在条件编译中找到了Adobe的文档(http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_21.html),它似乎应该解决它但我必须遗漏一些东西.

所以在我的ant构建文件中我有: -

<mxmlc
        file="${app.dir}/${application.name}.mxml"
        output="${dist.dir}/${application.name}.swf"
        context-root="${application.name}"
        debug="true"
        locale="${locales}"
        allow-source-path-overlap="true">
        <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
        <compiler.library-path dir="${lib.dir}" append="true">
            <include name="*.swc" />
        </compiler.library-path>
        <define name="BUILD::BuildNumber" value="'20100707.800'"/>
        <source-path path-element="${src.dir}"/>
        <source-path path-element="${cfg.dir}"/>
        <source-path path-element="${locale.dir}" />
</mxmlc>
Run Code Online (Sandbox Code Playgroud)

然后我试图检索

public static const buildNumber:String = BUILD::BuildNumber;
Run Code Online (Sandbox Code Playgroud)

但是编译器拒绝接受:

SomeModel.as(31):col:47错误:访问未定义的属性BUILD.
[mxmlc] private static const _buildNumber:String = BUILD :: BuildNumber;

有什么建议?

Chr*_*lsh 2

这里的其他建议的组合似乎有效。

这应该放在您的 build.xml 中(假设您的 build.xml 在此之前已经为 BUILD_NUMBER 分配了一个值):

<mxmlc>
    ...
    <define name="CONFIG::build" value="&quot;${BUILD_NUMBER}&quot;" />
    ...      
</mxmlc>
Run Code Online (Sandbox Code Playgroud)

请注意使用&quot;不带任何引号的 the。另请注意,您可以将此语法与 compc 一起使用。

然后你的动作脚本代码可以是这样的:

public static const buildNumber:String = CONFIG::build;
Run Code Online (Sandbox Code Playgroud)

我认为您不一定需要使用 CONFIG 命名空间,但这是一种流行的约定。