2008-09-16 60 views
7

编译MXML文件,我刚开始使用Flex和现在用的SDK(没有的Flex Builder)。我想知道从ant构建脚本中编译mxml文件的最佳方式是什么。与蚂蚁的Flex SDK

回答

10

Flex的SDK附带了一组Ant任务。更多信息在:

http://livedocs.adobe.com/flex/3/html/help.html?content=anttasks_1.html

以下是编译的Flex的SWC与蚂蚁的例子:

http://www.mikechambers.com/blog/2006/05/19/example-using-ant-with-compc-to-compile-swcs/

迈克室

+0

我可以在某处获得mxmlc SWC文件,还是必须自己编译它?我能够使用mxmlc ant标记编译actionscript,但相同的脚本不适用于mxml文件。我试图在我的目标中使用java jar文件,但没有成功。谢谢! – sutee 2008-09-17 21:41:45

5

我肯定会跟随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> 
3

还有另一种选择 - 这就是所谓的Project Sprouts

这是用Ruby,RubyGems的和耙,可提供许多在Maven和ANT发现功能,内置的系统,但有一个更清洁的语法和更简单的构建脚本。

例如,上面显示的ANT脚本应该是这样的豆芽:

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 

豆芽的另一个好处,一旦安装,是它提供的项目,阶级和测试发电机,将让任何开发箱准备用几个简单的命令行操作运行。

# 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 
+0

谢谢你介绍耙子,但我搜索了关于蚂蚁。顺便说一句,shell脚本“mxmlc”将是一行。 – chro 2011-09-23 14:14:09