In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

曲線を描く運動

Get Adobe Flash player
by _wonder 03 Jul 2010
    Embed
/**
 * Copyright _wonder ( http://wonderfl.net/user/_wonder )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/1Zf1
 */

// forked from _wonder's 加速してから減速する運動
// forked from _wonder's 減速する運動
// forked from _wonder's 加速する運動
// forked from _wonder's 等速運動
// forked from _wonder's base
package {
    import flash.display.Sprite;
    import flash.events.Event;
    
    public class FlashTest extends Sprite {
        private var ball:Ball;
        private var target:Ball;
        private var ax:Number = 0.005;//加速度
        private var ay:Number = 0.005;
        private var per:Number = 0.005;//加速度を増やす
        
        public function FlashTest() {
            target = new Ball(20);
            target.x = stage.stageWidth - 80;
            target.y = stage.stageHeight - 20;
            target.alpha = 0.3;
            addChild( target );
            
            ball = new Ball(20);
            ball.x = 20;
            ball.y = stage.stageHeight / 2;
            addChild( ball );
            
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
        
        private function onEnterFrame(e:Event):void {
            if( target.y > 80 ){
                target.y -= 10;
            }
            
            if( ball.x < target.x ){
                var dx:Number = target.x - ball.x;
                var dy:Number = target.y - ball.y;
                ax += per;
                ay += per;    
                ball.x += dx * ax;
                ball.y += dy * ay;
            }
        }
    }
}

import flash.display.Sprite;

class Ball extends Sprite {
    public var radius:Number;
    public var color:uint;
    
    public function Ball(radius:Number=40, color:uint=0Xff0000){
        this.radius = radius;
        this.color = color;
        init();
    }
    
    public function init():void {
        graphics.beginFill(color);
        graphics.drawCircle(0, 0, radius);
        graphics.endFill();
    }
}