2008年3月27日木曜日

flex3のEffectをMXMLでSequence

as3でもflex3のeffectが使える。

import mx.effects.Move;

とすれば as3で

var move:Move = new Move();
move.play([this]);

とflexのEffectを利用できる。

しかし よく使うEffectはMXMLで

<mx:Move yBy="-1" duration="50"/>

と書いた方が楽だしきれいに思う。 ただし Effectの記述は純粋にViewの記述とは言いがたいので Effect用途毎に 別ファイルとして記述したい。

そこで

<mx:Move xmlns:mx="http://www.adobe.com/2006/mxml"
         suspendBackgroundProcessing="true"
         yBy="-1" duration="50"/>

という内容でHogeEffect.mxmlとして保存すれば as3では

var hoge:HogeEffect = new HogeEffect();
hoge.play([this]);

newできる。

しかし Sequenceだとうまくいかなかった。

<mx:Sequence xmlns:mx="http://www.adobe.com/2006/mxml"
             suspendBackgroundProcessing="true">
  <mx:Move yBy="-1" duration="50"/>
  <mx:Move yBy="+2" duration="100"/>
  <mx:Move yBy="-1" duration="50"/>
</mx:Sequence>

とMXMLを記述しても (正しいはずだが) 子Effectが再生されない。 as3上でchilrenをみても空になっていた。

試行錯誤した結果

<mx:Sequence xmlns:mx="http://www.adobe.com/2006/mxml"
             suspendBackgroundProcessing="true">
  <mx:children>
    <mx:Move yBy="-1" duration="50"/>
    <mx:Move yBy="+2" duration="100"/>
    <mx:Move yBy="-1" duration="50"/>
  </mx:children>
</mx:Sequence>

と きちんとmx:chilrenで囲むと 動いた。

コメント(0):