Compiling mxml files with ant and flex sdk

孤街浪徒 提交于 2019-11-28 10:16:54

The Flex SDK ships with a set of ant tasks. More info at:

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

Here is an example of compiling Flex SWCs with ant:

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

mike chambers

I would definitely go with the ant tasks that are included with Flex, they make your build script so much cleaner. Here is a sample build script that will compile and then run your flex project

<?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>

There is another option - it's called Project Sprouts.

This is a system built with Ruby, RubyGems and Rake that provides many of the features found in Maven and ANT, but with a much cleaner syntax and simpler build scripts.

For example, the ANT script shown above would look like this in 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

After installing Ruby and RubyGems, you would simply call this script with:

rake

To remove generated files, run:

rake clean

To see available tasks:

rake -T

Another great benefit of Sprouts, once installed, is that it provides project, class and test generators that will get any development box ready to run with a couple simple command line actions.

# 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

If you're open to Maven, try the flex-compiler-mojo plugin:

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

Christiaan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!