as2ant

Using ANT files is to me one of the attractions of using open source flash. One of the things that I really like is the ability to be able to compile multiple swfs at once.

While working for the CSIRO a couple of years ago, I was developing 7 education type games (with a scientific emphasis). The games engine was constantly being improved and tweaked as the requirements for the games were really tough. Basically the games had to be completely accessible (tabIndex hell), all text had to be read as sound, they contained video and all of this had to load within 7 seconds (well the user wasn’t allowed to wait longer than 7 seconds initially so everything had to be streamed strategically). I ended up developing an extensive loading manager which was controllable and smart enough to know what to load next based on user interaction.

ANYWAY, my point is that the core engine which controlled these 7 games was constantly being improved. They of course all shared the same core class, but due to the nature of the flash IDE every time I made a change in the core code I had to compile every fla again. As you can imagine this became annoying. And worse because of the time pressures and dynamic deadlines it was hard to keep track of what had been recompiled and what hadn’t. 

Today with ANT builds this situation can easily be avoided. By using ANT you can have multiple projects compile with the single ANT build. In other words if the CSIRO games above were being developed in a osflash environment, every time there was a change to the core code, I would only need to run the one ant build which would compile all the movies. As you can imagine this saves so much time and mucking about.

This drawn out example :)  is to bring attention to simon wackers new as2ant release which you can read more about here. And find out how to implement here. Basically as2ant is a very smart and easy way to use ANT files to build flash movies. The latest release even allows you to include swfmill details within the one ANT build. Previously you had to include a separate swfmill xml for each movie.  I’m in the process of updating my old ANT files to use this latest version of as2ant, but as an example heres a ANT file using the previous version of as2ant. Its compiling 3 swfs using swfmill. I’ve included at the bottom a method for viewing the swfs in either firefox or the flashviewer. Obviously once I convert it to the new version of as2ant I wont need the separate swfmill files.


<project name="PhotoFade" default="compile" basedir=".">

<!– Declares references to needed directories. –>
<property name="src.dir" location="src"/>
<property name="build.dir" location="build"/>
<property name="logger.dir" location="C:\Program Files\eclipse\plugins\org.asdt.logger_0.0.8.build5\lib\flash_classes"/>
<property name="first.swf" value="HomePage"/>
<property name="second.swf" value="SubPage"/>
<property name="third.swf" value="Logos"/>

<!– Define the SWFMILL task –>

<exec executable="C:\swfmill\swfmill.exe">
<arg line="simple swfmill1.xml ${build.dir}\${ant.project.name}${first.swf}.swf"/>
</exec>
<exec executable="C:\swfmill\swfmill.exe">
<arg line="simple swfmill2.xml ${build.dir}\${ant.project.name}${second.swf}.swf"/>
</exec>
<exec executable="C:\swfmill\swfmill.exe">
<arg line="simple swfmill3.xml ${build.dir}\${ant.project.name}${third.swf}.swf"/>
</exec>

<!– Define the MTASC ant task –>
<taskdef name="mtasc" classname="org.as2lib.ant.Mtasc" classpath="C:\anttasks\src"/>

<!– Target that uses the MTASC Ant Task. –>
<!– header="${width}:${height}:${framerate}:${bgcolor}" –>
<target name="compile" description="builds swfs">
<mtasc src="${src.dir}/com/hugeobject/PhotoFade/Application${first.swf}.as" classpath="${src.dir}:${logger.dir}" swf="${build.dir}\${ant.project.name}${first.swf}.swf" main="true" trace="Log.addMessage"/>
<mtasc src="${src.dir}/com/hugeobject/PhotoFade/Application${second.swf}.as" classpath="${src.dir}:${logger.dir}" swf="${build.dir}\${ant.project.name}${second.swf}.swf" main="true" trace="Log.addMessage"/>
<mtasc src="${src.dir}/com/hugeobject/PhotoFade/Application${third.swf}.as" classpath="${src.dir}:${logger.dir}" swf="${build.dir}\${ant.project.name}${third.swf}.swf" main="true" trace="Log.addMessage"/>
</target>


<!– auto show the swf–>
<exec executable="C:\Program Files\Macromedia\Flash MX 2004\Players\SAFlashPlayer.exe">
<arg line="${build.dir}/${ant.project.name}.swf"/>
</exec>

<!– show the swf in a html page in firefox –>
<exec executable="C:\Program Files\Mozilla Firefox\firefox.exe">
<arg line="${build.dir}/${ant.project.name}_index.html"/>
</exec>

</project>


technorati tags: , ,

One Response to “as2ant”

  1. Jackson Says:

    Lieber grumble!!! hoffe dir gehts gut da in der fremden weite… wenn man dich schon nicht persænlich besuchen kann…

Leave a Reply