かえる君ぽよよーん

by ProjectNya
//////////////////////////////////////////////////////////////////////////////
かえる君ぽよよーん
//////////////////////////////////////////////////////////////////////////////
♥0 | Line 76 | Modified 2010-07-03 15:19:59 | MIT License
play

ActionScript3 source code

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

////////////////////////////////////////////////////////////////////////////////
// かえる君ぽよよーん
////////////////////////////////////////////////////////////////////////////////

package {

    import flash.display.Sprite;
    import flash.display.MovieClip;
    import flash.display.Loader;
    import flash.events.Event;
    import flash.net.URLRequest;
    import flash.system.Security;
    import flash.system.LoaderContext;
    import flash.utils.Timer;
    import flash.events.TimerEvent;

    [SWF(backgroundColor="#FFFFFF", width="465", height="465", frameRate="30")]

    public class Main extends Sprite {
        private var loader:Loader;
        private static var piyoPath:String = "http://www.project-nya.jp/images/flash/frogA.swf";
        private var Frog:Class;
        private var frog:MovieClip;
        private var amplitude:Number = 0;
        private static var basePos:uint = 780;
        private static var targetPos:uint = 480;
        private static var deceleration:Number = 0.6;
        private static var friction:Number = 0.8;
        private static var acceleration:Number = 0.4;

        public function Main() {
            //Wonderfl.disable_capture();
            Wonderfl.capture_delay(2);
            init();
        }

        private function init():void {
            Security.allowDomain("www.project-nya.jp");
            loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, complete, false, 0, true);
            loader.load(new URLRequest(piyoPath), new LoaderContext(true));
        }
        private function complete(evt:Event):void {
            loader.removeEventListener(Event.COMPLETE, complete);
            frog = MovieClip(evt.target.content);
            addChild(frog);
            frog.x = 232;
            frog.y = basePos;
            frog.shade.visible = false;
            frog.scaleX = frog.scaleY = 5;
            frog.addEventListener(Event.INIT, swingHead, false, 0, true);
            var timer:Timer = new Timer(1000, 1);
            timer.addEventListener(TimerEvent.TIMER_COMPLETE, jump, false, 0, true);
            timer.start();
            loader = null;
        }
        private function jump(evt:TimerEvent):void {
            evt.target.removeEventListener(TimerEvent.TIMER_COMPLETE, jump);
            frog.addEventListener(Event.ENTER_FRAME, slideIn, false, 0, true);
        }
        private function slideIn(evt:Event):void {
            amplitude += targetPos - frog.y;
            frog.y += amplitude*friction;
            amplitude *= deceleration;
            if (Math.abs(targetPos - frog.y) < 0.5 && Math.abs(amplitude) < 0.1) {
                amplitude = 0;
                frog.y = targetPos;
                frog.removeEventListener(Event.ENTER_FRAME, slideIn);
                frog.swingHead();
            }
        }
        private function swingHead(evt:Event):void {
            frog.addEventListener(Event.ENTER_FRAME, slideOut, false, 0, true);
        }
        private function slideOut(evt:Event):void {
            frog.y += (basePos - frog.y)*acceleration;
            if (Math.abs(basePos - frog.y) < 0.5) {
                frog.y = basePos;
                frog.removeEventListener(Event.ENTER_FRAME, slideOut);
                var timer:Timer = new Timer(3000, 1);
                timer.addEventListener(TimerEvent.TIMER_COMPLETE, jump, false, 0, true);
                timer.start();
            }
        }

    }

}