Archive for the ‘Workflow’ tag
Using ANT in your Flash Development Part 2: Basic ANT Concepts
This is the beginning of the “HOW” part, if you want the “WHY”, see my previous post in this series here.
You must define your ANT tasks in an xml file. Typically, this file is called “build.xml” and I like to put it in the root of my projects. Here’s the most basic example of such a file:
<project name=”Basic ANT”>
<target name=”Hello World”>
<echo>Well, hello world!</echo>
</target>
</project>
Running ANT in Eclipse
- Go ahead and create a build.xml file in your Eclipse project now. Paste the code above into the file and save.
- Go to the to menu and select Window->Show View->ANT (if you don’t already have the ANT window opened in your workspace)
- Drag the build.xml file from the Explorer Window to the ANT window.
- You will see the ANT task appear with the title defined in “project name” above, in this case “Basic ANT”. If you open it up, you will see a list of the targets defined in the ANT project.
- Double click on the Hellow World target (aka task).
- You will see something like this:

Hello World Output
The project (name, attributes) is defined in the <project name> node. You must define the name, and optionally the default target and the basedir (base directory) property. Here is a typical project node definition:
<project name=”FCNY USEFUL ANT Tasks” default=”CompileMain” basedir=”.”>
The targets are the actual tasks that get executed. Each target has a name and one or more task definitions.
A task is the bit of code that actually gets executed. There are a huge number of basic built-in tasks in the core library that include things like: basic file operations, echo, building filesets, etc. The tasks we’re interested in most are the Flex ANT tasks. These are what will allow us to compile Flash applications without using the IDE and to generate all manner of workflow tricks.
There is a huge library of optional tasks that are easy to add to do pretty much anything that can be done from the command line: ftp files to a server, perform version control operations, run unit tests, etc.
A property is the equivalent of a variable in ANT projects. The following line defines a property and uses the ${propname} syntax to reference the value of the “basedir” property defined in the property definition above:
<property name=”mainFLA” value=”${basedir}/MainAssets.fla”/>
It is good practice to use property definition files to define and group your properties. In my real world example, I have 2 property files: “default.properties” and “local.properties”. The first defines properties that are global to the project and will not change, such as default project structure settings. The latter defines properties that need to be edited for each users computer, such as the paths to their favorite web browser, the location of their Flex SDK, etc.
Task Dependencies
You can use dependencies to chain tasks together, so that they run in sequence. The concept of dependencies in ANT can be a little confusing. If you define a task “D”:
<target name="D" depends="C,B,A"/>
The target D tasks will be executed after C, B and A are executed, in the order specified. What can be odd is a situation like this:
<target name="C" depends="A, B"/> <target name="D" depends="A, B"/> <target name="F" depends="C, D"/>
If you were to run task F, you may expect to see tasks executed in this order: A, B, C, A, B, D.
But you’d be wrong! What you’d actually see is: A, B, C, D. When D is executed, it sees that the A and B tasks have already been executed, so it won’t run them again.
To use a target multiple times in a single invocation, you need to use antcall. This will allow you to treat targets more as subroutines.
The next blog will explain how the sample project is set up and begin detailing the many example tasks in the project.
Using ANT in your Flash Development and Be a Better Person! Part 1
OK, long time coming, but here we go. There’s too much material for one blog post, so I’m going to break it down over a few blog entries. This series is based on a talk that I gave to the fabulous flashcodersny group, on Aug 13 2008.
ANT is a fantastic tool for automating your Flash development workflow. ANT allows you to write powerful tasks to do just about anything you could desire: compiling Flash (AS2 or AS3), file system operations, ftp’ing files, setting version numbers, generate code documentation, play annoying sounds, etc.
I’ve been hearing about ANT for a while, but only came to adopting it after some frustration with the Flex Builder workflow. At my shop, we have Flash developers who use FDT and, more recently, Flex Builder. We like to check the final SWF into SVN when we have a release build. This allows us to just export a copy of our build files and push them to the server when we want to deploy. Works well enough, and it means that I don’t have to be present for weekend pushes!
I’ve heard compelling arguments about why putting SWFs into version control is a bad idea, but it’s really very convenient, and you don’t need a developer with the fully configured environment for deployments. Anybody who knows how to use the version control system can perform a deploy.
But, Flex Builder will not let you work this way! The default workflow creates a bin-debug folder where your compiled SWFs end up. You cannot check this directory into SVN. I understand their rationale for this, but it’s annoying, and has tripped up a lot of developers. And you can’t customize the workflow too much with Flex Builder, you have to do it their way. Also, the default version that Flex Builder compiles is a debug version, not a release version, so you would not want to check it in anyway. Also, I wanted our developers to be able to use FDT, Flash, or Flex Builder as they wished, on the same project, and the Flex Builder workflow made this difficult.
So, I turned to ANT to get around these issues, which I was able to work out. But, then I realized how much more I could get from ANT, and I find I’m using it more and more with every project, and it’s especially made my life much easier with complicated deployments (4 different server environments requiring different configurations). I’m using ANT on every project now and it’s become widely adopted in my department.
The solution to a unified workflow was to adopt ANT tasks for all Flash compilation. We compile projects the same way whether we’re using FDT, Flex Builder, or Flash. You can execute all of these tasks from within Eclipse, or from the command line if that’s how you roll. The entry on compiling Flash (AS2 or AS3) is part 4 of this series.
Part 2 will introduce basic ANT functionality and the files for my sample project.
Useful Links
You can get the full story on ANT here.
I found these 2 posts very useful for getting set up with ANT in Eclipse/Flex Builder:
Jody Brewster’s Installing Ant in Flex Builder 3
Ryan Taylor’s article on using ANT with FDT3