forked from: flash on 2010-2-27

by hemingway forked from flash on 2010-2-27 (diff: 1)
♥0 | Line 53 | Modified 2012-08-15 00:24:56 | MIT License
play

ActionScript3 source code

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

// forked from ushisantoasobu's flash on 2010-2-27
package{
    import flash.display.Sprite;
    
    public class BallAction extends Sprite{
        public function BallAction(){
            //var ball:Sprite = new BallSprite(0xFF9933);
            //ball.x=100;
            //ball.y=100;
            //addChild(ball);
            
            //var moveBall:Sprite=new MoveBallSprite(0xFF1122);
            //moveBall.x=20;
            //moveBall.y=20;
            //addChild(moveBall);
            
            //var dropBall:Sprite=new DropBallSprite(0xFF3434);
            //dropBall.x=0;
            //dropBall.y=0;
            //addChild(dropBall);
            
            var mouseBall:Sprite = new MouseTraceBallSprite(0x343434);
            mouseBall.x = 10;
            mouseBall.y = 10;
            addChild(mouseBall);
        }
    }
}

import flash.display.Sprite;
class BallSprite extends Sprite {
    public function BallSprite(color:uint) {
            super();           
           graphics.beginFill(color);
        graphics.drawCircle(0,0,20);
        graphics.endFill();
    }
}

import flash.events.*;
class MoveBallSprite extends BallSprite{
    public var velocityX:Number = 2;
    public var velocityY:Number = 3;
    public function MoveBallSprite(color:uint){
        super(color);
        addEventListener(Event.ENTER_FRAME, updataPosition);
    }
    private function updataPosition(e:Event):void{
        x += velocityX;
        y += velocityY;
    }
}

class DropBallSprite extends MoveBallSprite{
    public var gravity:Number = 0.6;
    public function DropBallSprite(color:uint){
        super(color);
        addEventListener(Event.ENTER_FRAME, upDateVelocity);
    }
    private function upDateVelocity(e:Event):void{
        velocityY += gravity;
    }
}

class MouseTraceBallSprite extends MoveBallSprite{
    public function MouseTraceBallSprite(color:uint){
        super(color);
        addEventListener(Event.ENTER_FRAME, updateVelocity);
    }
    private function updateVelocity(e:Event):void{
        velocityX = (root.mouseX-x)*0.1;
        velocityY = (root.mouseY-y)*0.1;
    }
}