flash on 2010-12-14

by asobuno2010
クリックするとまわりながら拡大して消えてく
♥0 | Line 38 | Modified 2010-12-14 13:24:18 | MIT License
play

ActionScript3 source code

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

// クリックするとまわりながら拡大して消えてく

package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.utils.Timer;
    
    public class Anime1 extends Sprite {
        public function Anime1():void {
            // クリックイベントを監視する
            stage.addEventListener("click", clickHandler);
        }

        private function clickHandler(event:MouseEvent):void {
            // 円を作成
            var s:Sprite = new Sprite();
            s.graphics.beginFill(Math.random() * 0x1000000);
            s.graphics.drawCircle(10, 0, 10);
            s.graphics.endFill();
            s.scaleX = s.scaleY = 0;
            addChild(s);

            // 円をクリックされた位置に移動
            s.x = event.stageX;
            s.y = event.stageY;
            
            // 回転の方向をランダムにさせる
            var kakudo:int = xGetRandomInt(-2, 2);
            function xGetRandomInt(nMin:Number, nMax:Number):int {
                var nRandom:int = Math.floor(Math.random() * (nMax-nMin+1))+nMin;
                return nRandom;
            }

            // タイマー開始
            var timer:Timer = new Timer(50, 20);
            timer.start();
            timer.addEventListener("timer", function(event:Event):void {
                var ratio:Number = timer.currentCount / timer.repeatCount;
                s.alpha = 1 - ratio;
                s.scaleX = 20 * ratio;
                s.scaleY = 20 * ratio;
                s.rotation = kakudo * 180 * ratio;
            });
            timer.addEventListener("timerComplete", function(event:Event):void {
                removeChild(s);
            });
        }
    }
}

Forked