TweensyでA→B→Cと順番にアニメーションさせたい

by yasai
sp1→sp2→sp3 という風に TweensyTimeline の onComplete を使って順番に動かしています。
* 実際、順番に動いてはいるのですが、アニメーションさせるinstanceが増えれば増えるほど
* このようにネストしてしまうものなのでしょうか?
* それとも、もっとスマートに書くイカした方法があるのでしょうか?
* to,from,fromtoはどうしても使いたいです。
* 詳しい方教えてください。
* よろしくお願いします。
* 
♥0 | Line 56 | Modified 2009-11-09 11:35:47 | MIT License
play

ActionScript3 source code

/**
 * Copyright yasai ( http://wonderfl.net/user/yasai )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/dW8y
 */

	/* sp1→sp2→sp3 という風に TweensyTimeline の onComplete を使って順番に動かしています。
	 * 実際、順番に動いてはいるのですが、アニメーションさせるinstanceが増えれば増えるほど
	 * このようにネストしてしまうものなのでしょうか?
	 * それとも、もっとスマートに書くイカした方法があるのでしょうか?
	 * to,from,fromtoはどうしても使いたいです。
	 * 詳しい方教えてください。
	 * よろしくお願いします。
	 * */
package {
	import com.flashdynamix.motion.*;
	import flash.display.Sprite;
	import fl.motion.easing.*;
	import flash.events.MouseEvent;
	import net.hires.debug.Stats;
	
    public class FlashTest extends Sprite {
        public function FlashTest() {
			addChild( new Stats() );
			init();
		}
		
		private function init():void 
		{
			//タダの丸
			var sp1:Sprite = makeSp();
			addChild(sp1);
			var sp2:Sprite = makeSp();
			addChild(sp2);
			var sp3:Sprite = makeSp();
			addChild(sp3);
			
			var tween:TweensyTimeline = new TweensyTimeline();
			
			//指定値へのトゥイーン
			tween = Tweensy.to(sp1, { x: getRandInt(), y: getRandInt() }, 5 );
			tween.delayEnd = 1.0;
			tween.onComplete = function():void { 
				//指定値からのトゥイーン
			    tween = Tweensy.from(sp2, { x: getRandInt(), y: getRandInt() }, 5 ); 
				tween.delayEnd = 1.0;
				tween.onComplete = function():void {
					//指定値から指定値への(ry
					Tweensy.fromTo(
						sp3,
						{ x: getRandInt(), y: getRandInt() },
						{ x: getRandInt(), y: getRandInt() },
						5
					); 
				}
		    }			
			
			//stageクリックでリセット
			stage.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void {
				stage.removeEventListener(MouseEvent.CLICK, arguments.callee);
				removeChild(sp1);
				removeChild(sp2);
				removeChild(sp3);
				init();
			});
        }
		
		//sp作る
		private function makeSp():Sprite {
			var sp:Sprite = new Sprite();
			sp.graphics.beginFill(Math.random()*0xDDDDDD);
			sp.graphics.drawCircle(0, 0, 10);
			sp.graphics.endFill();
			sp.x = stage.stageWidth / 2;
			sp.y = stage.stageHeight / 2;
			return sp;
		}
		
		//乱数吐く
		private function getRandInt(i:int = 465):int {
			return Math.random() * i;
		}
    }
}

Forked