6
votes

I'm trying to pass a build number from Hudson into a Flex application.

I've found Adobe's document (http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_21.html) on conditional compilation which seems it should solve it but I must be missing something.

So in my ant build file I have:-

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

Then i'm trying to retrieve with

public static const buildNumber:String = BUILD::BuildNumber;

However the compiler is rejecting with:

SomeModel.as(31): col: 47 Error: Access of undefined property BUILD.
[mxmlc] private static const _buildNumber:String = BUILD::BuildNumber;

Any suggestions?

4
Based on the docs regarding conditional compilation; it looks like you're doing things exactly right. I'm at a bit of a loss. livedocs.adobe.com/flex/3/html/… . Is the Flex Compiler turning your public static const into getter/setter methods w/ a private var? Could that conversion somehow cause the issue?JeffryHouser
Could be. It's now straight in the view. I can get it working in Flash Builder, with -define+=BUILD::BuildNumber,'00000000.000' in the additional commands section. It just doesn't get it passed through from the ant mxmlc build.Decado

4 Answers

2
votes

A combination of the other suggestions here seems to work.

This should go in your build.xml (it assumes that your build.xml has already assigned a value to BUILD_NUMBER before this point):

<mxmlc>
    ...
    <define name="CONFIG::build" value="&quot;${BUILD_NUMBER}&quot;" />
    ...      
</mxmlc>

Note the use of the &quot; without any quotation marks. Note also that you can use this syntax with compc.

Then your actionscript code can have something like this:

public static const buildNumber:String = CONFIG::build;

I don't think you necessarily need to use the CONFIG namespace, but it's a popular convention.

1
votes

It's definitely a quoting issue. I fought this for quite a while. However I use the tag in ant to run mxmlc and compc so not sure if my resolution is the same. This certainly works for me tho:

<arg value="-define+=ENV::build,&quot;${build.id}&quot;" />
<arg value="-define+=ENV::version,&quot;${build.version}&quot;" />

Can I suggest you try:

<define name="BUILD::BuildNumber" value="&quot;20100707.800&quot;"/>
0
votes

There's a comment by Laurynas Stančikas saying you should use &quot; :

To pass string with Ant (when using mxmlc task), use &quot;. For example:

    <compiler.define name="NAMES::AppName" value="&quot;'FooBar'&quot;" />

Have you tried that?

0
votes

I just solved a javascript flashvars problem with quotes, which inspired a "try this" idea:

Try escaping:

<compiler.define name="NAMES::AppName" value="\'FooBar\'" />