FlashAntTasks – Compiling Flash Movies With Ant

If you’ve seen Mike Chambers flashcommand implementation you’ll notice that it only works on the mac.  We have a lot of people at my office on Windows and I wanted to provide them something that could also work on a Windows computer.  Plus I wanted something a little cleaner, easier to learn and a bit more elegant than most of the solutions out there.  So I created FlashAntTasks.  Its a jar file that you reference in your class file that creates flash tasks that compile separate movies.  I’m posting it up on Google code so everyone can enjoy.  So enough with the fluff, here’s the details

WINDOWS USERS – you need to pass in flashcommand the flashapp attribute with the uri to your flash.exe like

You can download the code at http://code.google.com/p/flashanttasks/.

<?xml version="1.0" encoding="UTF-8"?>
<project name="FlashAntTasks" basedir="." default="Open in Browser">
 
    <description>
        simple example build file
    </description>
 
    <!-- os specific properties -->
    <property name="os" value="${os.name}"/>
    <echo message="Using ${os.name}.properties"/>
    <property file="${os.name}.properties"/>
 
	<!-- Include the Flash Ant Tasks Jar here, also make sure you 
                reference the FlashAntTasks.properties file which is 
                bundled in the jar file -->
    <taskdef resource="FlashAntTasks.properties" classpath="lib/FlashAntTasks.jar"/>
 
	<!-- Project Specific Properties -->
	<property name="html.filename" value="index_full.html" />
	<property name="local.path" value="${basedir}/wwwroot//${html.filename}" />
 
        <!-- make sure to reference the fla dir and your output dir -->
	<property name="fla.dir" value="${basedir}/flash" />
	<property name="swf.output.dir" value="${basedir}/wwwroot/assets/swfs" />
 
 
	<!-- TARGETS -->
	<target name="Compile Additional Swfs">
		<flashcommand >
			<movie export="true" source="${fla.dir}/site.fla" output="${swf.output.dir}/site.swf" />
			<movie export="true" source="${fla.dir}/shared.fla" output="${swf.output.dir}/shared.swf" />
		</flashcommand>
	</target>
 
	<target name="Compile Shell" depends="Compile Additional Swfs">
		<flashcommand >
			<movie export="true" source="${fla.dir}/shell.fla" output="${swf.output.dir}/shell.swf" />
		</flashcommand>
	</target>
 
	<target name="Windows Example" depends="Compile Additional Swfs">
                      <!-- WINDOWS USERS: flashapp attribute is required -->
		<flashcommand flashapp="c:\\Program files\\Adobe\\Flash.exe">
			<movie test="true" source="${fla.dir}/shell.fla" output="${swf.output.dir}/shell.swf" />
		</flashcommand>
	</target>
 
	<target name="Compile Shell" depends="Compile Additional Swfs">
		<flashcommand >
			<movie export="true" source="${fla.dir}/shell.fla" output="${swf.output.dir}/shell.swf" />
		</flashcommand>
	</target>
 
 
	 <!-- Open in local browser -->
	<target name="Open in Browser" depends="Compile Shell">
		<exec executable="open">
			<arg line="-a ${browser} ${local.path}" />
		</exec>
	</target>
 
</project>
  1. Thanks a lot for this. I have been using it for the last couple of days with great success.

    It would be great if the temp jsfl file would close the file it opened after it was published. Or maybe if you could specify if you want it closed. It should be as simple as adding to extra commands in the temp jsfl file that gets created.

    • matt
    • August 18th, 2009

    hey this is awesome dude, just what i need to publish about 200 flas :)

  2. @Julian – you can add the closeDocAfterComplete parameter to each movie node in the build.xml.

    • Joe
    • November 28th, 2009

    Hello,

    This task is really great. Reaaly cool to have the source too.
    I have just found a bug in a special case. When your build file, is not named exactly “build.xml”, the task crash.

    • Daniel Zollinger
    • March 9th, 2010

    Nice work. Cheers for this!

    I’m having a little trouble, as Flash hangs on me, but I suspect this is Flash’s crappiness and not the project.

    Anyway, thanks for taking the time to share your work.

  3. Jody,
    After a long day of searching for a way to achieve this (what FlashAntTasks does), I finally came across FAT. It works perfectly with CS5 so I was super happy to get that going as all that I’ve tried today just didn’t work with Flash CS5. However, one thing that I noticed is that sometimes when I run the Ant task it gets terminated after the “Compile Additional SWFs” target, as in:

    Buildfile: /Users/mprzybylski/Work/Personal/FDT 4 Tests/source/build.xml
    Compile Additional SWFs:
    [flashcommand] Compiling /Users/mprzybylski/Work/Personal/FDT 4 Tests/source/fla/main.fla

    After that I have the Compile Shell which doesn’t run. This happens sometimes, and sometimes the build is successful. I’d hate to have to keep running it until it finally works, so do you have any idea why this would be happening?

    Also, what are the chances of (or how would I) bringing the newly created test SWF into focus so I don’t have to alt+tab over to Flash IDE to see it?

    Great work,
    Matt

  1. No trackbacks yet.