MyIgnorance 2011-10-22
今天学习并试验了三种利用Ant将mxml编译成swf的方法
使用Ant编译mxml的几种方法:
1.可执行版的exec
<?xmlversion="1.0"?>
<projectname="FlexAntTasksBuildScript"default="compileMain">
<!--propertyfile="build.properties"/-->
<propertyname="dir.src"value="src"/>
<propertyname="dir.build"value="build"/>
<propertyname="FLEX_HOME"value="D:/ProgramFiles/Adobe/FlexBuilder3Plug-in/sdks/3.2.0"/>
<targetname="init">
<deletedir="${dir.build}"/>
<mkdirdir="${dir.build}"/>
</target>
<targetname="compileMain"depends="init"description="Compilesthemainapplicationfiles.">
<echomessage="Compiling${dir.build}/main.swf..."/>
<execexecutable="${FLEX_HOME}/bin/mxmlc.exe"spawn="false">
<argline="${dir.src}/main.mxml"/>
<argline="-output${dir.build}/main.swf"/>
</exec></target>
</project>
2.Java版
<?xmlversion="1.0"?>
<projectname="FlexAntTasksBuildScript"default="compileMain">
<!--propertyfile="build.properties"/-->
<propertyname="dir.src"value="src"/>
<propertyname="dir.build"value="build"/>
<propertyname="FLEX_HOME"value="D:/ProgramFiles/Adobe/FlexBuilder3Plug-in/sdks/3.2.0"/>
<targetname="init">
<deletedir="${dir.build}"/>
<mkdirdir="${dir.build}"/>
</target>
<targetname="compileMain"depends="init"description="Compilesthemainapplicationfiles.">
<echomessage="Compiling${dir.build}/main.swf..."/>
<javajar="${FLEX_HOME}/lib/mxmlc.jar"fork="true"failonerror="true">
<argvalue="+flexlib=${FLEX_HOME}/frameworks"/>
<argvalue="-file-specs=${dir.src}/main.mxml"/>
<argvalue="-output=${dir.build}/main.swf"/>
</java></target>
</project>
3.使用Flex3SDK中的mxmlc任务
为了能访问所要build文件中的信息,首先添加一个任务定义
<?xmlversion="1.0"?>
<projectname="FlexAntTasksBuildScript"default="compileMain">
<!--propertyfile="build.properties"/-->
<propertyname="dir.src"value="src"/>
<propertyname="dir.build"value="build"/>
<propertyname="FLEX_HOME"value="D:/ProgramFiles/Adobe/FlexBuilder3Plug-in/sdks/3.2.0"/>
<taskdefresource="flexTasks.tasks"classpath="${FLEX_HOME}/ant/lib/flexTasks.jar"/>
<targetname="init">
<deletedir="${dir.build}"/>
<mkdirdir="${dir.build}"/>
</target>
<targetname="compileMain"depends="init"description="Compilesthemainapplicationfiles.">
<echomessage="Compiling${dir.build}/main.swf..."/>
<mxmlcfile="${dir.src}/main.mxml"output="${dir.build}/main.swf">
<source-pathpath-element="${dir.src}"/>
</mxmlc></target>
</project>
以上swf的output文件目录可以不指定,如不指定,默认为mxml所在目录