使用Ant和Flex SDK编译MXML文件
时间:2020-03-05 18:57:28 来源:igfitidea点击:
我刚开始使用flex,正在使用SDK(而不是Flex Builder)。我想知道从ant构建脚本编译mxml文件的最佳方法是什么。
解决方案
回答
Flex SDK附带了一组ant任务。有关更多信息,请访问:
http://livedocs.adobe.com/flex/3/html/help.html?content=anttasks_1.html
这是使用ant编译Flex SWC的示例:
http://www.mikechambers.com/blog/2006/05/19/example-using-ant-with-compc-to-compile-swcs/
迈克·钱伯斯
回答
如果我们愿意使用Maven,请尝试flex-compiler-mojo插件:
http://code.google.com/p/flex-mojos/
克里斯蒂安
回答
我绝对会选择Flex随附的ant任务,它们使构建脚本更加整洁。这是一个示例构建脚本,将编译然后运行flex项目
<?xml version="1.0"?> <project name="flexapptest" default="buildAndRun" basedir="."> <!-- make sure this jar file is in the ant lib directory classpath="${ANT_HOME}/lib/flexTasks.jar" --> <taskdef resource="flexTasks.tasks" /> <property name="appname" value="flexapptest"/> <property name="appname_main" value="Flexapptest"/> <property name="FLEX_HOME" value="/Applications/flex_sdk_3"/> <property name="APP_ROOT" value="."/> <property name="swfOut" value="dist/${appname}.swf" /> <!-- point this to your local copy of the flash player --> <property name="flash.player" location="/Applications/Adobe Flash CS3/Players/Flash Player.app" /> <target name="compile"> <mxmlc file="${APP_ROOT}/src/${appname_main}.mxml" output="${APP_ROOT}/${swfOut}" keep-generated-actionscript="true"> <default-size width="800" height="600" /> <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/> <source-path path-element="${FLEX_HOME}/frameworks"/> <compiler.library-path dir="${APP_ROOT}/libs" append="true"> <include name="*.swc" /> </compiler.library-path> </mxmlc> </target> <target name="buildAndRun" depends="compile"> <exec executable="open"> <arg line="-a '${flash.player}'"/> <arg line="${APP_ROOT}/${swfOut}" /> </exec> </target> <target name="clean"> <delete dir="${APP_ROOT}/src/generated"/> <delete file="${APP_ROOT}/${swfOut}"/> </target> </project>
回答
还有另一个选项叫做Project Sprouts。
这是一个由Ruby,RubyGems和Rake构建的系统,提供了Maven和ANT中的许多功能,但语法更简洁,构建脚本也更简单。
例如,上面显示的ANT脚本在Sprouts中看起来像这样:
require 'rubygems' require 'sprout' desc 'Compile and run the SWF' flashplayer :run => 'bin/SomeProject.swf' mxmlc 'bin/SomeProject.swf' do |t| t.input = 'src/SomeProject.as' t.default_size = '800 600' t.default_background_color = '#ffffff' t.keep_generated_actionscript = true t.library_path << 'libs' end task :default => :run
安装Ruby和RubyGems之后,只需使用以下命令调用此脚本:
rake
要删除生成的文件,请运行:
rake clean
要查看可用任务:
rake -T
一旦安装,Sprouts的另一个巨大好处就是它提供了项目,类和测试生成器,这些生成器将使我们可以使用几个简单的命令行操作就可以运行任何开发工具。
# Generate a project and cd into it: sprout -n mxml SomeProject cd SomeProject # Compile and run the main debug SWF: rake # Generate a new class, test case and test suite: script/generate class utils.MathUtil # Compile and run the test harness: rake test