swfを試す。
キャストオブジェクトはインスタンスidとインスタンスグループで参照と抽出ができます。インスタンスidはidプロパティ、インスタンスグループはgroupプロパティで設定します。
次のサンプルでは、BallCastSpriteクラスで円形のキャストスプライト、BoxCastSpriteクラスでは四角形のキャストスプライトを作り、合計20個のキャストスプライトをステージに交互に並べています。このとき、BallCastSpriteクラスで作ったキャストスプライトにはグループidとして"ball"を付け(22行目)、BoxCastSpriteクラスで作ったキャストスプライトにはグループidとして"box"を付けます(28行目)。同時に個々を区別する"sp0"〜"sp19"のインスタンスidも付けます(21、27行目)。
続いてキャストスプライトにアニメーションを付けるコマンドリストを作成します。まず1つ目のアニメーションとして、getInstancesByGroup("ball")でインスタンスグループballのキャストスプライトを配列ballListに参照を取り出し(40行目)、1個ずつ順に弾むように拡大するアニメーションをDoTweenerコマンドで作りシリアルリストのanimeList1に追加します。
同様に2つ目のアニメーションはgetInstancesByGroup("box")でインスタンスグループboxのキャストスプライトを配列boxListに参照を取り出し(47行目)、すべてが同時にぐるんと90度回転するアニメーションをDoTweenerコマンドで作りパラレルリストanimeList2に追加します。
3つ目のアニメーションでは、今度はランダムに選んだidのキャストスプライトをgetInstanceById("sp"+no)を使って1個だけ取り出し(54行目)、そのキャストスプライトが拡大縮小を繰り返すアニメーションをループリストanimeList3を使って作ります。
3種類のアニメーションの準備ができたので、最後にこれらを順に実行します(59行目)。実行はシリアルリストになるので、animeList1が完了したならばanimeList2、最後にanimeList3という順で再生されます。
[:script:]グループとインスタンスidでインスタンスを選択してアニメーションする
package {
import jp.progression.commands.display.*;
import jp.progression.commands.*;
import jp.progression.scenes.*;
import jp.progression.casts.getInstanceById;
import jp.progression.casts.getInstancesByGroup;
import jp.progression.commands.tweens.DoTweener;
import jp.progression.commands.lists.*;
import pages.*
public class IndexScene extends SceneObject {
public function IndexScene() {
//ブラウザのタイトル。
title = "Top";
//コンテンツ
var castSp:*;
for (var i:int=0;i < 20;i++){
if(i%2){
//偶数番のキャストを作る
castSp = new BallCastSprite();
castSp.id = "sp"+i; //インスタンスid
castSp.group = "ball";//インスタンスグループ
castSp.scaleX=castSp.scaleY=0.4;
}else{
//奇数番のキャストを作る
castSp = new BoxCastSprite();
castSp.id = "sp"+i;//インスタンスid
castSp.group = "box";//インスタンスグループ
}
//キャストをコンテナに並べる
castSp.x = i%5*100+40;
castSp.y = int(i/5)*90+40;
(new AddChild(container, castSp)).execute();
}
}
//このシーンをロードしたらアニメーションを開始する
protected override function atSceneLoad():void {
//インスタンスグループballのアニメーションのコマンドリストを作る
var ballList:Array = getInstancesByGroup("ball");
var animeList1:SerialList = new SerialList();
for (var i:int=0;i < ballList.length;i++){
animeList1.addCommand( new DoTweener(ballList[i],{scaleX:1,scaleY:1,time:0.5,transition:"easeOutElastic"}));
animeList1.addCommand( new DoTweener(ballList[i],{scaleX:0.4,scaleY:0.4,time:0.5,transition:"easeOutElastic"}));
};
//インスタンスグループboxのアニメーションのコマンドリストを作る
var boxList:Array = getInstancesByGroup("box");
var animeList2:ParallelList = new ParallelList();
for (var j:int=0;j < boxList.length;j++){
animeList2.addCommand( new DoTweener(boxList[j],{rotation:90,time:1,transition:"easeOutElastic"}));
}
//インスタンスidを1個選んでアニメーションをループさせる
var no:int = Math.floor(Math.random()*20);
var sp:* = getInstanceById("sp"+no) ;
var animeList3:LoopList = new LoopList();
animeList3.addCommand(new DoTweener(sp,{scaleX:1.5,scaleY:1.5,time:1,transition:"easeOutElastic"}));
animeList3.addCommand(new DoTweener(sp,{scaleX:0.4,scaleY:0.4,time:1,transition:"easeOutElastic"}));
//コマンドリストの実行
addCommand(animeList1, animeList2, animeList3);
}
}
}










