Building Flash Projects with Ant and Flex Builder – Part 2
In Part 2 of this tutorial, we’ll compile an ActionScript 3 only project simply by launching the MXMLC compiler with an Ant task in Flex Builder.
1. Download tutorial files
To begin this tutorial, please make sure you have set up your workspace as suggested in Part 1.
2. Examine Demo2.as
Demo2.as is exactly the same as Demo1.as in Part 1 of this tutorial. Except this time around, we do not have an FLA linked to Demo2 as its document class.
package
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
public class Demo2 extends Sprite
{
public function Demo2()
{
var format:TextFormat = new TextFormat();
format.font = "Arial";
format.size = 16;
format.color = 0x000000;
var label:TextField = new TextField();
label.width = 500;
label.defaultTextFormat = format;
label.text = "Welcome to my ANT Demo!";
label.x = 100;
label.y = 150;
addChild( label );
}
}
}
3. Examine build.xml
The compileMain task here launches the MXMLC compiler with the Demo2.as file as its argument and outputs demo2.swf.
<target name="compileMain">
<echo>Compiles Demo2.as file and outputs demo2.swf</echo>
<mxmlc file="${SRC_DIR}/Demo2.as" output="${DEPLOY_DIR}/demo2.swf"
actionscript-file-encoding="UTF-8"
incremental="false"
debug="true"
default-frame-rate="31"
default-background-color="0xCCCCCC">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
<source-path path-element="${SRC_DIR}" />
<!-- Set size of output SWF file. -->
<default-size width="550" height="400" />
</mxmlc>
</target>
Coming up
This is a quick and painless one, isn’t it? In Part 3, we’ll use a combination of the MXMLC compiler and JSFL script to compile an external SWF which will be loaded into your main SWF.
March 20th, 2009 at 5:54 am
Hi
I’ve just started migrating my Flex builds to Ant, and have come across some unusual error/warning reports. It seems that all errors & warnings are output as type “warn”, and the final output showing the number of errors (e.g. “Result: 10″) is output as type “error” (if there were errors).
I’m using this with CruiseControl, so build reports are automatically emailed to me – but I can’t easily tell the errors and warnings apart, because errors aren’t highlighted in red like they should be.
Do you know what I might be doing wrong? Is there config to specify that errors should be logged as type “error”?
I’d really appreciate your help on this! I’m fairly new to building Flex in Ant, so I’m a little confused.
Thanks!
Stuart
April 8th, 2009 at 5:40 pm
@Stuart I’m no Ant expert myself so I’m sorry to say that I don’t have an answer to your question. If I come across anything that explains your problem, I’ll be sure to post it.
January 11th, 2010 at 5:14 am
[...] http://hubflanger.com/building-flash-projects-with-ant-and-flex-builder-part-2/ [...]
March 8th, 2010 at 6:30 am
Thanks for your excellent tutorials :)
Could you be so kind as to advise me what would be causing this error, I followed all your advice in your posts.
BUILD FAILED
H:\My Documents\Flash Builder 4\AS3_Ant_Tutorial_Part2\build.xml:39: Problem: failed to create task or type mxmlc
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.
Total time: 312 milliseconds
March 8th, 2010 at 7:08 am
my mistake
March 8th, 2010 at 7:08 am
name=”FLEX_HOME” value=”C:\Program Files\Adobe\Adobe Flash Builder Beta 2\sdks\3.4.1″
July 7th, 2010 at 5:41 am
Thanks for the tutorial, it has been really helpful…
Can you advise me on how to go about setting the file dynamically?
I have multiple ‘applications’ within an actionscript project and wish to use Ant to compile them each independently without having to change the build file each time