Skip to content

ANT and Flex

by Colin on May 4th, 2010

EDIT
You can view the documentation I created here.

While writing my framework about 6 months ago, I wanted to create ASDocs for it so anyone using the framework would know how to work with it. I also love the idea of compiling all the source into a SWC file to make sending that source very easy to do. It's a very cumbersome process to create ASDocs and compile to a SWC through the executable files by itself, and upon research discovered ANT.
For those who don't know, ANT can be seen as the middle man between you and sending commands to a Java build tool. From there, you send ANT an XML file of the commands to run to the appropriate Java file. Sound easy? Heck ya it is.
I use Flex, however you can install ANT with any Eclipse based IDE. Please note, the majority of my build.xml is a combination of source I've found on multiple blogs, this post is the verdict of what I've learned with what I've found.
First, let's create out XML document. Title it "build.xml". The "project name" is the name reference you'll see in the ant window.

  1.  

Second, we want to create variables within the script so it makes referencing files and folders easier.

  1. <!-- CREATE THE VARS -->
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11. <!-- SWC Related -->
  12.  
  13.  
  14.  
  15. <!-- AS DOC Related -->
  16.  
  17.  
  18.  

Here you'll see I'm referencing where the .exe ("asdoc.exe") and .jar ("flexTasks.tasks") files exist on my machine so ant knows how to use the compiler. I also reference where my project is located, as well as the source folder ("src") and output folders("output.swc" and "output.docs").

Note
I have periods delimit spaces with my variables with ANT, however you can name them however you want: "outputSWC", "output.swc", "output-swc" as examples.

Next, I'm going to tell ANT what functions it'll need to run. First and foremost, I want ANT to not "think" about overwriting files, so I'll delete a directory, then recreate it to save it the trouble. After that's done, I'll have it create the docs and the swc.

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8. <!-- runs the asdoc.exe compiler on the source -->
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16. ASDOC created successfully
  17.  

The first function is "clean-asdoc-directory", which deletes the directory then recreates it. We'll use the same functionality for compiling the SWC. Next, we have it create the documentation by running our ASDoc executable file. Each "arg line" is an argument that's sent to the executable so it receives the required variables. As you can see about, I have many "${}" lines, which are references to the "property" (aka variables) we created above. We also want the executable build to fail if there's any problems at all.

Now, let's compile that swc.

  1. <!-- deletes and recreates the swc directory -->
  2.  
  3.  
  4.  
  5.  
  6.  
  7. <!-- generate the swc -->
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23. SWC created successfully
  24.  
  25.  

The beauty about this "generate-swc" method is that it compiles all .as files within your "src" directory, whereas normally you would either have to manually input each class or each package.
You can download the final result here.

From → Flex

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS