Skip to main content

Building a Flex project with Ant

Here is a quick sample on how to build a simple Flex
"hello world" project with Ant.

The "hello world" project contains a src folder with one Flex application file and an Ant build.xml file:


The app.mxml is the main module of the project. It simply has a label with a "Hello World!" text:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="" layout="absolute">
<mx:Label text="Hello World!"/>
Here is the build.xml source:
<?xml version="1.0"?>
<project name="fx_practice7" default="all">

<!-- Init the build process -->
<target name="init" unless="initialized">
<!-- Name of project and version -->
<property name="FLEX_HOME" location="/Users/mykola/java/flex"/>

<property name="" value="${}" />
<property name="proj.shortname" value="${}" />
<property name="version.major" value="0" />
<property name="version.minor" value="9" />
<property name="version.revision" value="0" />
<property name="APP_TITLE" value="Sample Application" />
<property name="APP_WIDTH" value="800" />
<property name="APP_HEIGHT" value="600" />

<!-- Global properties for this build -->
<property name="build.dir" location="${basedir}/build" />
<property name="flex_src" location="${basedir}/src" />

<path id="project.classpath">
<pathelement path="${java.class.path}" />

<taskdef resource="flexTasks.tasks"
classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />


<property name="initialized" value="true" />

<mkdir dir="${build.dir}" />

<!-- Default target: clean and build the application -->
<target name="all" depends="init">
<antcall target="clean" />
<antcall target="build" />

<!-- Compile Flex files -->
<target name="compile.flex" depends="init">
<property name="module"
description="The name of the application module." />

<mxmlc file="${flex_src}/${module}.mxml"
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml" />
<source-path path-element="${FLEX_HOME}/frameworks" />
<compiler.source-path path-element="${flex_src}" />

<html-wrapper title="${APP_TITLE}"
output="${build.dir}/${}/" />


<!-- Build the application -->
<target name="build" depends="init">
<antcall target="compile.flex" />

<!-- Clean build files -->
<target name="clean" depends="init">
<delete dir="${basedir}/generated" />
<delete dir="${build.dir}" />

<target name="usage" description="Usage documentation">
all - clean and build the project
NOTE: Please update FLEX_HOME and other properties in the build.xml as required for your environment.

To do the build, simply run ant in the project folder. The build output will be stored in the project/build/ folder. To see the result, open index.html in a browser. The index.html is located in the project/build/project_home/ folder.


Anonymous said…
Thanks for post, it has useful information. My question is, what do I do if I have Javascript classes in my index.html file? Using FlexBuilder you can edit the index.html.template and add my Javscript methods here, which I can then call from my Flex app. How would I go about doing the same thing using ant?

Anonymous said…
Just a small correction to my previous post. It should of course have said, "what if I have javascript methods in the index.html" not javascript classes

Mykola said…
I guess there are 2 options - either change the template in the SDK folder or change the generated index.html. The second is probably a better option. The Flex livedocs chapter called "Using the html-wrapper task" says: "You can customize the output of the wrapper and its supporting files after it is generated by Ant." That task can be automated with ant as well.

Really nice tips!

will try to keep it in my mind


Popular posts from this blog

cucumber-jvm and Android Studio

During this Winter holidays, I've been exploring a Behavior Driven Development and experimented with a couple of testing frameworks: Calabash and cucumber-jvm.

In this post, I would like to describe setting up cucumber-jvm for Android Studio projects.

I've extended cucumber-jvm examples with a version for Android Studio. Here is a copy in my github branch:

In addition to the example code, here is some details on how it was created.

The cucumber-jvm requires several libraries to be added to a project:

I've found it's easier to add those dependencies with the Android Studio project setup dialog because it takes care of the jar versions for you.

File > Project Structure > Modules > app > Dependencies > + > Library dependency
  > type "cucumber" in the s…

Flash on Google Sites

This is a brief how-to add a Flash on a Google Site.

Google Sites allows adding Flash embedded into a Google Gadget. I uploaded a swf file to my Google Site - FlexWebTools and found a gadget that allows displaying any SWF on a Google Site page. It is called AnyFlash. It is pretty easy to use and it worked fine in my Firefox 3.5.5 on Mac OS X 10.5.8. Then I send a link to my site to my friends and they discovered that the SWF was not displayed properly on IE6 and in Firefox on Linux. I reviewed AnyFlash source code and eventually found that there is a bug 939 in the Google Gadget API. Therefore, I created a new gadget that does not use the gadgets.flash.embedFlash() method and works well with Firefox, Safari and IE6 browsers on Mac, Windows and Linux.

While working on the gadget, I found a few different ways of embedding Flash into a gadget. Some of them are pretty straightforward like simply pointing to a swf in the context tag. Some are more sophisticated. For instance, they would …

How to debug SOAP on Mac with tcpdump

I’ve been using several tools to debug SOAP on Mac and Windows. I would like to share my experience in using some of the tools and show some examples.

So far I found four major categories of tools that are useful in debugging SOAP:
Interface listeners such as tcpdump and othersProxy tools such as TCPMonitorServlet filtersApplication server logging. For example, Weblogic has a special logging option that dumps SOAP requests and responses to the sever log.
All of these tools have their own advantages and disadvantages. In this article, I will describe the first type - an interface listener tool called tcpdump. I am planning to describe other three categories in the future posts.

The tcpdump is a tool that sniffs IP traffic and dumps it to a file or a standard output stream. It was originally developed by Van Jacobson, Craig Leres and Steven McCanne from the Lawrence Berkeley National Laboratory, University of California, Berkeley, CA. It is open source. The tcpdump documentation and sou…