2008/12/11

Flash Player 10依存のFlexプロジェクトをAntでビルド

Flash Player 10(Astro)依存のAPIを使ったコードをAntでビルドしようとしたら、mxmlcタスクで下記のようなエラーに遭遇したよ。
エラー: 未定義である可能性が高いプロパティ data に静的型 flash.net:FileReference の参照を使用してアクセスしています。
エラー: 未定義である可能性のあるメソッド load を、静的型 flash.net:FileReference の参照を使用して呼び出しました。

なんでだろうと調べてみると、flex-config.xmlにしっかりとFlash Playerのバージョンが設定されていたことにより、「このSWFは9.0.124から実行できますよ」となっていたことが原因だった。

C:¥Program Files¥Adobe¥Flex Builder 3¥sdks¥3.2.0¥frameworks¥flex-config.xml
<flex-config>
<!-- Specifies the minimum player version that will run the compiled SWF. -->
<!-- 9.0.124 is the April 2008 security release -->
<target-player>9.0.124</target-player>

そこで、「このSWFは10.0.12からじゃないと実行できませんよ」と書いてあげれば解決するのだけど、このファイルを変更した場合、他のプロジェクトも影響を受けてしまうので対象プロジェクト専用にflex-config.xmlを作ってあげる。
<flex-config>

<target-player>10.0.12</target-player>

</flex-config>

Flex Builder上では下記のように追加コンパイルオプションを設定する。

プロジェクトのプロパティ - Flexコンパイラ - 追加コンパイル引数
-load-config+=C:¥workspace¥hoge¥flex-config.xml

build.xmlには、mxmlcタスクにload-configを追加してflex-config.xmlをロードさせる。
 <target name="build">
<mxmlc file="src/Hoge.mxml"
actionscript-file-encoding="UTF-8"
debug="false" optimize="true"
output="bin-release/Hoge.swf">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<load-config filename="flex-config.xml"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
<source-path path-element="resources/locale/{locale}" />
<compiler.library-path dir="${FLEX_HOME}/frameworks" append="true">
<include name="libs" />
</compiler.library-path>
<compiler.library-path dir="libs" append="true">
<include name="swc" />
</compiler.library-path>
</mxmlc>
</target>

こんなんでFlash Player 10依存のプロジェクトをビルドできたよ。

0 件のコメント: