views:

2487

answers:

1

I'm building a Flex application that will need run under two different deployment scenarios:

First, the application will be hosted on the web. The SWF loads some external resources (images, text) so it requires network access, which is the Flex Builder 3 default build flag "-use-network=true". I don't need to do anything special; it just works.

Second, the application will be written to CD with autorun enabled to launch the index.html hosting the SWF. The SWF still needs to be able to load those same external resources, which reside on the CD in a subfolder. Since those files are on the CD, they are considered local, so Flash security requires the SWF to be built using a flag of "-use-network=false". I add that to the "Additional compiler arguments" text box found under "Flex Compiler" in the Flex project's Properties dialog.

That all works as expected, but it's tedious to have to manually modify the Flex Builder project settings to add or remove that flag as the case may be.

Ideally, I would like to just build the project once and have multiple output folders: one for the network deployment scenario, and another for the local deployment scenario.

What's the best way to do that? Is moving to an Ant build the way to go, or is there a simpler way? If an Ant build configuration is the correct way, do you have an example to share of such multiple build configurations?

Thanks for your help!

+5  A: 

Once you get your head around the Ant build, it will make your life a lot easier. Building a multiple build file is no different from a single build file, you will just add an additional task inside of your build with the appropriate settings (you could also use a loop in ant, but that adds complexity)

So, expanding on the Flex Ant Tasks example from the docs, something like this should work (not-tested):

<?xml version="1.0" encoding="utf-8"?>
<!-- myMXMLCBuild.xml -->
<project name="My App Builder" basedir="." default="main">
    <taskdef resource="flexTasks.tasks" classpath="${basedir}/flexTasks/lib/flexTasks.jar" />
    <property name="FLEX_HOME" value="C:/flex/sdk"/>
    <property name="APP_ROOT" value="apps"/>
    <property name="DEPLOY_DIR" value="c:/jrun4/servers/default/default-war"/>
    <target name="main" depends="clean, compile1, compile2">
    </target>
    <target name="compile1">
        <mxmlc 
            file="${APP_ROOT}/Main.mxml" 
            output="${DEPLOY_DIR}/Main.swf"
            actionscript-file-encoding="UTF-8"
            keep-generated-actionscript="true"
            incremental="true"
      use-network="true"
        >
            <!-- Get default compiler options. -->
            <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>

            <!-- List of path elements that form the roots of ActionScript
            class hierarchies. -->
            <source-path path-element="${FLEX_HOME}/frameworks"/>

            <!-- List of SWC files or directories that contain SWC files. -->
            <compiler.library-path dir="${FLEX_HOME}/frameworks" append="true">
                <include name="libs" />
                <include name="../bundles/{locale}" />
            </compiler.library-path>

            <!-- Set size of output SWF file. -->
            <default-size width="500" height="600" />
        </mxmlc>
    </target>
    <target name="compile2">
        <mxmlc 
            file="${APP_ROOT}/Main.mxml" 
            output="${CD_DEPLOY_DIR}/Main.swf"
            actionscript-file-encoding="UTF-8"
            keep-generated-actionscript="true"
            incremental="true"
      use-network="false"
        >
            <!-- Get default compiler options. -->
            <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>

            <!-- List of path elements that form the roots of ActionScript
            class hierarchies. -->
            <source-path path-element="${FLEX_HOME}/frameworks"/>

            <!-- List of SWC files or directories that contain SWC files. -->
            <compiler.library-path dir="${FLEX_HOME}/frameworks" append="true">
                <include name="libs" />
                <include name="../bundles/{locale}" />
            </compiler.library-path>

            <!-- Set size of output SWF file. -->
            <default-size width="500" height="600" />
        </mxmlc>
    </target>
    <target name="clean">
        <delete dir="${APP_ROOT}/generated"/>
        <delete>
            <fileset dir="${DEPLOY_DIR}" includes="Main.swf"/>
        </delete>
    </target>
</project>

As a side note, if you are going to be running the Ant build in eclipse/Flash Builder you might as well increase the memory now.

Joel Hooks