Although initially you can build your actionscript files using the "Run as" command, you will eventually want to automate your build process to allow you to build your project so you can do things like making various build for production or release. I use it for copy my build to my local web server so I can do testing against PHP.
What you need to do is create build.xml in the root folder of your project. You should also create a build.properties there as well, which the build.xml can read variables from and use. These properties are updated based on your different environment (i.e. where you put the flex compiler)
My build xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://java-aap.blogspot.com/2007/06/how-to-build-ant-scripts-for-flex.html -->
<project name="Flex Ant File Compiler" default="masterbuild" basedir=".">
<!-- Load Environment specific properties from properties file -->
<property file="build.properties" />
<property environment="env" />
<property name="FLEX_HOME" value="${env.FLEX_HOME}" />
<!-- Load the flex tasks for compiling the actionScript code and running flexUnit -->
<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/${FLEX.TASK.DIR}" />
<!-- Init with echoing some info to the console -->
<target name="init" description="Initializes the build">
<tstamp/>
<echo message="============================================="/>
<echo message="${project.name}-${project.version} [${TODAY}]"/>
<echo message="Copyright (c) ${project.year} ${project.owner}"/>
<echo message="OS : ${os.name}" />
<echo message="Author: ${author}" />
<echo message="=============================================="/>
</target>
<!-- Compile Modules -->
<target name="module" depends="init" description="Compiles related modules">
<mxmlc
file="${src.dir}/astonModule.mxml"
output="${bin.dir}/astonModule.swf"
keep-generated-actionscript="false"
incremental="false">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<load-config filename="${config.dir}/main-config.xml"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
<compiler.source-path path-element="${src.dir}"/>
<compiler.include-libraries dir="${basedir}" append="true">
<include name="${lib.dir}" />
</compiler.include-libraries>
</mxmlc>
</target>
<!-- Compile Main application -->
<target name="compile" depends="init" description="Compiles the mxml/as source files">
<mxmlc
file="${main.class}"
output="${swf.export}"
keep-generated-actionscript="false"
incremental="false"
>
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<load-config filename="${config.dir}/main-config.xml"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
<compiler.source-path path-element="${src.dir}"/>
<compiler.include-libraries dir="${basedir}" append="true">
<include name="${lib.dir}" />
</compiler.include-libraries>
</mxmlc>
</target>
<!-- Run unit test -->
<target name="unit-tests" depends="init" description="Compiles and runs the tests">
<mxmlc
file="${flex.unit.runner}"
output="${flex.unit.swf}"
keep-generated-actionscript="false"
incremental="false"
>
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
<compiler.source-path path-element="${src.dir}"/>
<compiler.include-libraries dir="${lib.dir}" append="true">
<include name="FlexUnit.swc" />
</compiler.include-libraries>
</mxmlc>
</target>
<!-- Generate ASDOC
<target name="doc" depends="init" description="Generates the asdoc of the source files">
<java className="${asdoc.tool}" fork="true" failonerror="true">
<classpath >
<fileset dir="${FLEX_HOME}/asdoc/lib" includes="*.jar" />
<fileset dir="${FLEX_HOME}/lib" includes="*.jar" />
</classpath>
<jvmarg line="-Dapplication.home=${FLEX_HOME} -Xms32m -Xmx768m -Dsun.io.useCanonCaches=false -Xbootclasspath/p:${FLEX_HOME}/asdoc/lib/xalan.jar"/>
<arg line="-library-path+='${basedir}/${lib.dir}/Cairngorm.swc'"/>
<arg line="-library-path+='${basedir}/${lib.dir}/flexunit.swc'"/>
<arg line="-library-path+='${basedir}/${lib.dir}/corelib.swc'"/>
<arg line="-library-path+='${basedir}/${lib.dir}/FlexUnitOptional.swc'"/>
<arg line="-library-path+='${FLEX_HOME}/frameworks/libs'"/>
<arg line="-library-path+='${FLEX_HOME}/frameworks/locale/en_US'"/>
<arg line="-doc-sources '${src.dir}'" />
<arg line="-main-title '${asdoc.docsname}'" />
<arg line="-window-title '${asdoc.docsname}'" />
<arg line="-output '${docs.asdoc.dir}'" />
<arg line="-footer 'CONFIDENTIAL. Copyright 2007 Your Company'" />
</java>
</target> -->
<!-- Clean output dirs -->
<target name="clean" description="clean all generated files">
<delete includeemptydirs="true">
<fileset dir="${bin.dir}" includes="**/*" />
</delete>
</target>
<!-- Create HTML wrapper -->
<target name="wrapper" depends="compile" description="Creates the HTML wrapper">
<!-- Copy the html-wrapper dir except the index.template.html -->
<copy todir="${bin.dir}">
<fileset dir="${wrapper.dir}">
<exclude name="**/index.template.html" />
</fileset>
</copy>
<!-- Copy and rename the index.template.html -->
<copy file="${wrapper.dir}/index.template.html"
tofile="${html.file}" />
<!-- Replace placeholders in the html with our variables -->
<replaceregexp
file="${html.file}"
flags="gs"
match="\$\{width\}"
replace="100%"/>
<replaceregexp
file="${html.file}"
flags="gs"
match="\$\{height\}"
replace="100%"/>
<replaceregexp
file="${html.file}"
flags="gs"
match="\$\{title\}"
replace="{project.name}"
encoding="utf-8"/>
<replaceregexp
file="${html.file}"
flags="gs"
match="\$\{version_major\}"
replace="9"/>
<replaceregexp
file="${html.file}"
flags="gs"
match="\$\{version_minor\}"
replace="0"/>
<replaceregexp
file="${html.file}"
flags="gs"
match="\$\{version_revision\}"
replace="0"/>
<replaceregexp
file="${html.file}"
flags="gs"
match="\$\{application\}"
replace="${application.name}"/>
<replaceregexp
file="${html.file}"
flags="gs"
match="\$\{bgcolor\}"
replace="#FFFFFF"/>
<replaceregexp
file="${html.file}"
flags="gs"
match="\$\{swf\}"
replace="${application.name}"/>
</target>
<!-- Run all, default -->
<!-- depends="clean, compile, unit-tests, wrapper" -->
<!-- depends="clean, module, compile, unit-tests" -->
<target name = "deploy-local" depends="compile">
<copy file="${swf.export}" todir="${local.dir}" />
</target>
<target name="masterbuild"
depends="compile,deploy-local"
description="Complete build in efficient sequence"/>
</project>
My build properties, which can change based on your environment:
######################################
## Project information
######################################
author = Terence Tan
project.owner = Big Bad Robots
project.owner.url = http://www.bigbadrobots.com
project.fullname = Manhattan Murder Mystery
project.version = 0.0.1 # major.minor[.revision[.build]]
project.name = mmm
project.year = 2010
application.name = Manhattan Murder Mystery
### Flex Task
FLEX.TASK.DIR= ant/lib/flexTasks.jar
######################################
## Properties
######################################
src.dir=src
bin.dir=deploy
build.dir=build
lib.dir=lib
config.dir=config
local.dir=/home/terence/bbrfacebook.homelinux.com/mmm
main.class = ${src.dir}/main.mxml
swf.export = ${bin.dir}/main.swf
######################################
## Flex Unit
######################################
flex.unit.runner = ${src.dir}/test.mxml
flex.unit.swf=${basedir}/${bin.dir}/test.swf
report.dir=${basedir}/doc/junitreport
