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

SimplePong

Simple Pong
Click : start
Mouse : Move
Get Adobe Flash player
by tanzi 02 Feb 2009
// Simple Pong
// Click : start
// Mouse : Move
package {
	import flash.display.*;
	import flash.events.*;
	[SWF(width="320", height="320", backgroundcolor="0xffffff", frameRate="30")]
	public class Pong extends Sprite {
		private var bar:Shape = new Shape();
		private var ball:Shape = new Shape();
		private var bvx:int=5, bvy:int=5;
		public function Pong(){
			this.addEventListener(Event.ENTER_FRAME, update);
			bar.graphics.beginFill(0x000000);
			bar.graphics.drawRect( -20, 4, 40, 8);
			bar.y = 290;
			addChild(bar);
			ball.graphics.beginFill(0x000000);
			ball.graphics.drawRect( -4, -4, 8, 8);
			ball.x = 160; ball.y = 320;
			addChild(ball);
			stage.addEventListener(MouseEvent.CLICK, init);
		}
		public function update(event:Event):void {
			bar.x = stage.mouseX;
			if (ball.x<4 || ball.x>(316)) bvx=-bvx;
			if (ball.y < 5) bvy = -bvy;
			if ((ball.y == 290) && (ball.x > bar.x - 24) && (ball.x < bar.x + 24)) bvy = -bvy;
			if (ball.y > 320) {
				ball.y = 320;
				bvx = 0;
			}
			ball.x += bvx; ball.y += bvy;
		}
		public function init(event:MouseEvent):void {
			if (ball.y < 320) return;
			ball.y = 5;
			bvx = 5;
		}
	}
}