Compiling mxml files with ant and flex sdk

I am just starting out with flex and using the SDK (not Flex Builder). I was wondering what is the best way to compile the mxml file from the ant build script.

+7
flex mxml ant
source share
4 answers

The Flex SDK comes with ant tasks. Additional Information:

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

Here is an example compiling Flex SWC with ant:

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

microphone cameras

+10
source share

I would definitely go with the ant tasks that are included in Flex, they make your build script so much cleaner. Here is an example build script that will compile and then execute the 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> 
+5
source share

There is another option - it is called Project Sprouts .

It is a system built with Ruby, RubyGems, and Rake that provides many of the features found in Maven and ANT, but with a much more syntactic and simpler build script.

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 simply invoke this script with:

 rake 

To delete the generated files, run:

 rake clean 

To see the available tasks:

 rake -T 

Another great advantage Sprouts once installed is that it provides project, class, and test generators that will get any development box ready to run with a few simple steps on the command line.

 # 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 
+3
source share

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

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

Christiaan

0
source share

All Articles