Flash IDE and Ant

August 29th, 2008

I have been promising to do a large multi-part posting on Ant and workflows and all of this great stuff but I haven’t gotten to it. Well if you remember I have just started a new job I have been really slammed trying to get things in order. One of the issues I am dealing with is how to automate builds of a site built entirely in the Flash CS 3 IDE. Well for those who know me, I am not a happy camper when I can’t have everything automated so I did a little digging on google and came across FlashCommands by Mike Chambers on Google Code. Well seeing how this python script lets you compile FLAs from the command line using Flash CS 3 I decided I would share with you my Ant script to automate the entire process.

One of the cool things about Ant is its ability to let you string together multiple command line tasks. What you are about to see is my solution to automating each compiling of the site’s FLA:

  • Compile the main FLA using the Flash CS3 IDE into my Sites folder to test on my local Apache setup
  • Move the compiled swc (I use this in FDT to compile against so I don’t get errors) back into my lib/swcs folder.
  • Compile the Fonts swf, for run time font sharing
  • Open my web browser and point it to my local copy of the site.
  • Finally, open my console and clear the trace log - see this post on getting console tracing on OS X.

Now onto the Ant Build:

<?xml version=“1.0″?>

<project name=“Default” default=“compile” basedir=“../”>
        <!– project specifics –>
        <property name=“browser” value=“Safari”/>
        <property name=“doc.class” value=“TommyGlobal”/>
        <property name=“swf.filename” value=“main”/>
        <property name=“html.filename” value=“index” />
       
        <!– Flash IDE Commandline compiler –>
        <property name=“python” value=“/usr/bin/python” />
        <property name=“flash.command” value=“${basedir}/build/flashcommand” />
       
        <!– directories –>
        <property name=“user.path” value=“/Users/jessefreeman”/>
        <property name=“build.dir” value=“${basedir}/build” />
        <property name=“deploy.dir” value=“${basedir}/deploy” />
        <property name=“swc.dir” value=“${basedir}/lib/swcs” />
        <property name=“fla.dir” value=“${basedir}/lib/flas”/>
        <property name=“site.dir” value=“${user.path}/Sites/tommy-pub/swf”/>
        <property name=“src.dir” value=“${basedir}/src”/>
       
        <property name=“main.fla” value=“${fla.dir}/TommyGlobal.fla” />
        <property name=“fonts.fla” value=“${fla.dir}/FontsLibrary.fla” />
        <!– paths –>
        <property name=“output.path” value=“${site.dir}/${swf.filename}.swf” />
        <property name=“swc.path” value=“${site.dir}/${swf.filename}.swc” />
        <property name=“font.path” value=“${site.dir}/FontsLibrary.swf” />
        <property name=“local.path” value=“http://tommy.local/”/>
        <property name=“log.path” value=“${user.path}/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt”/>
       
        <!– Compile python flashcommand -e  -s ../lib/flas/TommyGlobal.fla -o ../deploy/test.swf
               
        usage: flashcommand -e | -c | -p [-v] [-x] (-s <sourcefile>
) ([-o] <exportpath>) ([-t] <timeout>)([-d] <tempdir>) [-j]

        Options and arguments:
       
        -a : Prints version and about information.
        -c : Specifies save and compact action.
        -d : Specifies temp directory that will be used for temporary files. Optional.
        -e : Specifies export action.
        -h : Prints usage information.
        -j : Specifies that the generated JSFL file should be printed. If this option is specified, Flash will not be executed.
        -o : Specifies the output file if -e flag is also set. Optional. If not specified, file will be output to same directory as source.
        -p : Specifies publish action.
        -s : Specifies source file. Required.
        -t : Specifies timeout value. Optional.
        -v : Specifies verbose mode. Optional.
        -f : Specifies that the Flash authoring version installed is a version other than Flash CS3
        -x : Specifies whether Flash should be closed after it is done processing. Optional.   
               
        –>
       
        <target name=“compile” >
                <exec executable=“${python}” failonerror=“true”>
                        <arg line=“${flash.command}” />
                        <arg line=“-e “ />
                        <arg line=“-c “/>
                        <arg line=“-s ${main.fla} “/>
                        <arg line=“-o ${output.path}”/>
                </exec>
                <!– move the swc back into the correct folder –>
                <move file=“${swc.path}” todir=“${swc.dir}”/>
        </target>
       
        <target name=“fonts” >
                <exec executable=“${python}” failonerror=“true”>
                        <arg line=“${flash.command}” />
                        <arg line=“-e “ />
                        <arg line=“-c “/>
                        <arg line=“-s ${fonts.fla} “/>
                        <arg line=“-o ${font.path}”/>
                </exec>
        </target>
       
        <!– Open in local browser –>
        <target name=“local_open”>
                <exec executable=“open”>
                        <arg line=“-a ${browser} ${local.path}” />
                </exec>
        </target>
       
        <!– Clear Debug Log –>
        <target name=“clearlog”>

        <concat destfile=“${log.path}”>                                                                                                           
.: Tommy Log File :.

</concat>
                <exec executable=“open”>
                        <arg line=“-a console ‘${log.path}’” />
                </exec>
        </target>
</project>

Now I am not going to get into Ant or the details about this build file but I thought if anyone was inclined to read up on Ant in FlexBuilder, and download FlashCommands they could use this as a good starting point for automating builds from the Flash CS 3 IDE.

One thing to know, this only works on OS X and is still really slow. If you have a FLA that takes ages to compile in the IDE you are going to see the same long build times. As far as I know there is no way to speed up the Flash IDE. As you will see this build literately opens up Flash CS 3 for you along with the file and does a compile. What is cool about the script is that since the python script controls Flash you can alter its build path in the Ant script and come up with different build scenarios based on your needs. There is a lot of untapped power in this Ant Script, I really want to thank Mike for putting up such a cool and simple to use python script!

One Response to “Flash IDE and Ant”

  1. ezineaerticles » Blog Archive » Flash IDE and Ant Says:

    [...] Original post by FlashBum [...]

Leave a Reply