当我们的类库在Flex Builder中可以编译通过时,那自动化编译(ant)主要是根据在Flex Builder中设置的参数一致,基本就可以采用compc命令编译出一个swc文件。在编译过程中可能会遇到各种问题,不过不要烦躁,找到每个问题的原因,自然就找到了解决办法,下面总结一下在做Flex自动化编译过程中遇到的问题,希望可以帮助到大家。 在做ant编译之前,先看一下工程的具体信息,右键工程—属性,切换到Flex Library Build Path中,我们可以看到四个选项卡,Classes\Assers\Source Path\Library Path,那也就是说明我们用编写脚本的时候只需要指定这四项就可以了,另外,在Flex Library Compiler中可以看到是en_US\zh_CN,证明要做中英文资源化,因此我们自动化编译的时候需要将资源化文件引入,具体国际化会在后面介绍。 1. Flex Embed资源错误Unable to transcode asset处理 <mx:Image id="img_border" source="@Embed('../assets/border.png')" visible="false" width="100%" height="100%"/> 一段简单的代码flex编译居然报错: Unable to transcode ../assets/border.png. 解决方法很简单, 将 '../assets/border.png' 改为 '/../assets/border.png' 就是在前面加个斜杠。 2. Flex国际化 首先先介绍下国际化: Flex国际化一般采用的是类似struts的bundle类似的方法,至于好处嘛会使用STRUTS的人都应该知道。 默认为-locale en_US。 举个例子吧: 如果编译的时候没有引用资源文件,则会报相应的资源文件未找到。 在build.xml中添加资源文件即可 <source-path path-element="${project.dir}/locale/en_US"/> <source-path path-element="${project.dir}/locale/zh_CN"/> 3. 编译后的mx文件夹下所有图片大小为0字节 Mx中包括controls和container文件夹,主要包括用到的Flex控件的图片,因此需要在source-path中指定图片的位置,否则找不到图片,大小就为0喽; 加入以下脚本即可: <source-path path-element="${projects.framework}/src"/> 大概目录位置是E:\Program Files\Adobe\Flex Builder 3\sdks\3.2.0\frameworks\projects\framework\src 里面包括一个mx文件夹,是Flex用到的所有资源图片的存在位置。 4. 工程目录中包括mxml时编译不到swc中 因为我们编译的时候首先是读取src文件夹中的所有类,然后指定compc参数的include-classes参数,这时只是指定的所有as文件,而mxml是不属于某个包里面的,因此这里需要使用include-sources参数来指定。 具体代码如下: <include-sources dir = "${project.dir}\src\com\supermap\web\controls" includes = "Compass.mxml" /> Build.xml文件内容如下所示: <project name="Web.swc" basedir="." default="main" > <taskdef resource="flexTasks.tasks" classpath="E:\Flex\flexTasks\lib\flexTasks.jar" /> <property name="FLEX_HOME" value="E:\Progra~1\Adobe\FlexBu~1\sdks\3.2.0" /> <property name="project.dir" value ="E:\FlexProject\FlexClient60\FlexClientLib" /> <property name="output.file" value="Web.swc" /> <property name="projects.framework" value="E:\Program Files\Adobe\Flex Builder 3\sdks\3.2.0\frameworks\projects\framework"/> <target name="main" depends="clean, log, compc" /> <!-- deletes and recreates the compc directory --> <target name="clean"> <delete dir="${project.dir}\compile" failonerror="true"/> <mkdir dir="${project.dir}\compile"/> <echo>${Root}\bin</echo> </target> <!-- runs the compc.exe compiler on the source --> <target name="compc"> <echo>${Root}/src</echo> <fileset dir="${project.dir}\src" id="src.files"> <include name="**\**"/> </fileset> <pathconvert property="evaFramework_classes" pathsep=" " dirsep="." refid="src.files" > <map from="${project.dir}\src\" to=""/> <mapper> <chainedmapper> <globmapper from="*.as" to="*"/> </chainedmapper> </mapper> </pathconvert> <!--输出所有类--> <echo>${evaFramework_classes}</echo> <!--开始编译类库文件--> <compc output="${project.dir}\compile\${output.file}" locale="en_US,zh_CN" include-classes="${evaFramework_classes}" optimize="true" benchmark="true" strict = "true" debug="true" as3="true" actionscript-file-encoding = "utf-8" allow-source-path-overlap = "true" use-resource-bundle-metadata = "true" > <source-path path-element="${project.dir}/src" /> <!--如果类库做了国际化,那么需要引入国际化资源文件,也就是工程目录\locale\下面的所有资源文件(类型为.properties)--> <source-path path-element="${project.dir}/locale/en_US"/> <source-path path-element="${project.dir}/locale/zh_CN"/> <source-path path-element="${projects.framework}/src"/> <!-- List of SWC files or directories that contain SWC files. --> <!—注意这里可以指定类库文件的目录啊,呵呵--> <compiler.include-libraries dir="${FLEX_HOME}" append="true"> <include name="/frameworks"/> </compiler.include-libraries> <compiler.include-libraries dir="${project.dir}" append="true"> <include name="/lib" /> </compiler.include-libraries> </compc> </target> <!-- writes compc output to log file: compc-log.log --> <target name="log"> <record name="${project.dir}\compile\compc-log.log" action="start" append="true" /> </target> </project>
http://livedocs.adobe.com/flex/3/html/help.html?content=anttasks_1.html |
|