forked from: TweensyでA→B→Cと順番にアニメーションさせたい
forked from TweensyでA→B→Cと順番にアニメーションさせたい (diff: 19)
まったく同じ動きだと難しいなあ。ネストしちゃってる。 sp1→sp2→sp3 という風に TweensyTimeline の onComplete を使って順番に動かしています。 * 実際、順番に動いてはいるのですが、アニメーションさせるinstanceが増えれば増えるほど * このようにネストしてしまうものなのでしょうか? * それとも、もっとスマートに書くイカした方法があるのでしょうか? * 詳しい方教えてください。 * よろしくお願いします。 *
ActionScript3 source code
/**
* Copyright nacookan ( http://wonderfl.net/user/nacookan )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/sSB9
*/
// まったく同じ動きだと難しいなあ。ネストしちゃってる。
// forked from yasai's TweensyでA→B→Cと順番にアニメーションさせたい
/* sp1→sp2→sp3 という風に TweensyTimeline の onComplete を使って順番に動かしています。
* 実際、順番に動いてはいるのですが、アニメーションさせるinstanceが増えれば増えるほど
* このようにネストしてしまうものなのでしょうか?
* それとも、もっとスマートに書くイカした方法があるのでしょうか?
* 詳しい方教えてください。
* よろしくお願いします。
* */
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);
Tweensy.to(sp1, { x: getRandInt(), y: getRandInt() }, 5, Quintic.easeOut, 0, null, function():void{
Tweensy.from(sp2, { x: getRandInt(), y: getRandInt() }, 5, Quintic.easeOut, 1, null, function():void{
Tweensy.fromTo(
sp3,
{ x: getRandInt(), y: getRandInt() },
{ x: getRandInt(), y: getRandInt() },
5, Quintic.easeOut, 1
);
});
});
//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;
}
}
}
