Flex を使い始めたばかりで、SDK (Flex Builder ではありません) を使用しています。Ant ビルド スクリプトから mxml ファイルをコンパイルする最良の方法は何かと考えていました。
4 に答える
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プロジェクトをコンパイルして実行するサンプルビルドスクリプトです。
<?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>
別のオプションがあります - それは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 のもう 1 つの大きな利点は、インストールすると、プロジェクト、クラス、およびテスト ジェネレーターが提供され、いくつかの簡単なコマンド ライン アクションで任意の開発ボックスを実行できるようになることです。
# 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