7

我刚刚开始使用 flex,并且正在使用 SDK(不是 Flex Builder)。我想知道从 ant 构建脚本编译 mxml 文件的最佳方法是什么。

4

4 回答 4

10

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/

迈克室

于 2008-09-16T23:12:55.413 回答
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>
于 2008-10-21T15:42:36.280 回答
3

还有另一种选择 - 它称为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
于 2009-11-03T23:55:06.600 回答
0

如果您对 Maven 开放,请尝试使用 flex-compiler-mojo 插件:

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

克里斯蒂安

于 2008-09-17T06:22:37.253 回答