forked from: base

by _wonder forked from base (diff: 29)
♥0 | Line 44 | Modified 2010-05-27 12:24:08 | MIT License
play

ActionScript3 source code

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

// forked from _wonder's base
package {
    import flash.display.Sprite;
    import flash.events.Event;
    
    public class FlashTest extends Sprite {
    		private var ball1:Ball;
    		private var ball2:Ball;
    		
        public function FlashTest() {
            
            init();
        }
        
        private function init():void{
        		ball1 = new Ball();
        		addChild( ball1 );
        		ball1.x = stage.stageWidth / 2;
        		ball1.y = stage.stageHeight / 2;
        		
        		ball2 = new Ball();
        		addChild( ball2 );
        		ball2.startDrag();
        		
        		addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
        
        private function onEnterFrame(e:Event):void {
        		var dx:Number = ball2.x - ball1.x;
        		var dy:Number = ball2.y - ball1.y;
        		var dist:Number = Math.sqrt(dx*dx + dy*dy);
        		if( dist < ball1.radius + ball2.radius ){
        			ball1.x = 100;
        		}
        }
    }
}

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();
	}
}

Forked