Specifications
182
CHAPTER 9
Using Flex Ant tasks
You can use the Flex Ant tasks in your existing projects or create new Ant projects that use them. There are three
tasks that you can use in your Ant projects:
• mxmlc — Invokes the application compiler. You use this compiler to compile Flex applications, modules,
resource modules, and CSS SWF files.
• compc — Invokes the component compiler. You use this compiler to compile SWC files and Runtime Shared
Libraries (RSLs).
• html-wrapper — Generates the HTML wrapper and supporting files for your Flex application. By using this
task, you can select the type of wrapper (with and without deep linking support, with and without express install,
and with and without player detection), as well as specify application settings such as the height, width, and
background color.
To use the custom Flex Ant tasks in your Ant projects, you must add the flexTasks.jar file to your project's lib
directory, and then point to that JAR file in the
taskdef task. A taskdef task adds a new set of task definitions
to your current project. You use it to add task definitions that are not part of the default Ant installation. In this
case, you use the
taskdef task to add the mxmlc, compc, and html-wrapper task definitions to your Ant instal-
lation. In addition, for most projects you set the value of the
FLEX_HOME variable so that Ant can find your flex-
config.xml file and so that you can add the frameworks directory to your source path.
Use the Flex tasks in Ant:
1 Add a new taskdef task to your project. In this task, specify the flexTasks.tasks file as the resource, and point
to the flexTasks.jar file for the classpath. For example:
<taskdef resource="flexTasks.tasks"
classpath="${basedir}/flexTasks/lib/flexTasks.jar" />
2 Define the FLEX_HOME and APP_ROOT properties. Use these properties to point to your Flex SDK’s root
directory and application's root directory. Although not required, creating properties for these directories is a
common practice because you will probably use them several times in your Ant tasks, for example:
<property name="FLEX_HOME" value="C:/flex/sdk"/>
<property name="APP_ROOT" value="myApps"/>
3 Write a target that uses the Flex Ant tasks. The following example defines the main target that uses the mxmlc
task to compile the Main.mxml file:
<target name="main">
<mxmlc file="${APP_ROOT}/Main.mxml" keep-generated-actionscript="true">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>










