由于自己对Flex了解也不太多,现在针对Flex library项目进行Ant打包工作,主要还是写写自己完成过程中碰到的问题。
Flex编译环境:
Ant运行时环境:ANT_OPTS = -Xmx1024m -Xms1024m -Xmn512m -Xss128k -XX:NewRatio=4 -XX:SurvivorRatio=4 -XX:MaxPermSize=256m -XX:MaxTenuringThreshold=0(项目多时必要设置)
Flex在使用Ant进行编译时,最大的问题来源于Flex自身的编码规则,本人在编写Ant脚本的时候,大部分时间在调整代码的规则,例如:
1、 错误:
Embed(source="assets/ico/row.png")
正确:
Embed(source="/assets/ico/row.png")
错误的编写方式有可能会造成无法找到资源文件,采用正确的编写方式一定不会出错!
2、 错误:
var a:int = 10, b:int = 20;
正确:
var a:int = 10; var b:int = 20;
编码方式切不可以Java照搬!
3、 错误:
var a:int;
正确:
var a:int = 10;
变量一定要初始化!
Flex的编译方式总结将慢慢积累,暂时碰到这些问题。
推荐大家参考官方文档:http://livedocs.adobe.com/flex/3/html/help.html?content=configuring_environment_3.html
Ant code例子:
<target name="test.compile" depends="clean.bin"> <!-- 将flex源文件拷贝到编译路径 --> <copy todir="${build.bin}"> <fileset dir="${test.src}" /> </copy> <!-- 编译flex文件,输出到制定路径 --> <compc output="test.swc" debug="false" optimize="true" locale="en_US,zh_CN" actionscript-file-encoding="UTF-8" > <!-- 指定项目的源码目录 --> <source-path path-element="${build.bin}" /> <source-path path-element="${build.bin}/locale/{locale}" /> <!-- 指定编译的文件列表 --> <include-sources dir="${build.bin}"> <include name="**/*.as" /> <include name="**/*.mxml" /> </include-sources> <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml" /> <!-- 将Flex SDK 作为外部库进行引用 --> <compiler.external-library-path dir="${FLEX_HOME}/frameworks"> <include name="**/*.swc" /> </compiler.external-library-path> <!-- 将外部库进行引用,并且将swc文件代码编译到test.swc中 --> <library-path file="${release.swc}/gTest.swc" append="true"/> <library-path file="${release.swc}/bTest.swc" append="true"/> </compc> <echo message="test.compile --> 发布 Flex Library test成功" /> </target>