当前位置:首页> 正文

使用Ant和Flex SDK编译MXML文件

使用Ant和Flex SDK编译MXML文件

Compiling mxml files with ant and flex sdk

我刚开始使用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/

麦克·钱伯斯


我肯定会使用Flex随附的ant任务,它们使您的构建脚本更加整洁。这是一个示例构建脚本,将编译然后运行您的flex项目

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?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">
           
           
        </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中将如下所示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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之后,您只需使用以下命令调用此脚本:

1
rake

要删除生成的文件,请运行:

1
rake clean

查看可用任务:

1
rake -T

Sprouts的另一个巨大好处是,安装后,它可以提供项目,类和测试生成器,这些生成器将使您可以使用几个简单的命令行操作就可以运行任何开发工具。

1
2
3
4
5
6
7
8
9
10
11
12
# 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

如果您愿意使用Maven,请尝试使用flex-compiler-mojo插件:

http://code.google.com/p/flex-mojos/

克里斯蒂安


展开全文阅读

相关内容