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

Escape

Get Adobe Flash player
by hi_noon 05 Mar 2009
package {
	import flash.display.StageScaleMode;
	import flash.display.StageAlign;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;

	public class Main extends Sprite {
		private var tf:TextField;
		private var cont:Sprite;
		private var ary:Array = [];

		private var mX:Number = 5;
		private var mY:Number = 5;
		private var W:int = 30;
		private var H:int = 30;

		private var x0:Number;
		private var y0:Number;
		private var dx:Number;
		private var dy:Number;
		private var d:Number;

		private var _VS:Number = 0.2;
		private var _S:Number  = 2000;

		public function Main() {
			tf = new TextField();
			tf.autoSize = TextFieldAutoSize.LEFT;
			tf.textColor = 0x000000;
			tf.defaultTextFormat = new TextFormat( "_sans", 9 );
			report();
			addChild(tf);
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			cont = new Sprite();
			create(W, H);
			stage.addEventListener(MouseEvent.MOUSE_DOWN, clickHandler);
			stage.addEventListener(Event.RESIZE, screenHandler);
		}
		private function create(yoko:int = 10, tate:int = 10):void {
			addChild(cont);
			var W:Number = 2;
			var H:Number = 2;
			var color:uint = 0x000000;

			var len:int = yoko * tate;
			var row:int = yoko;
			var X:Number = new Number();
			var Y:Number = new Number();
			for (var i:int = 0; i < len; i++) {
				var block:Sprite = new Sprite();
				block.graphics.beginFill(color);
				block.graphics.drawRect(0, 0, W, H);
				block.graphics.endFill();
				X = block.width;
				Y = block.height;
				X = i % row == 0 ? 0 : (X + mX) * (i % row);
				Y = Math.floor(i / row) * (Y + mY);
				block.x = X;
				block.y = Y;

				var pram:Object = new Object();
				pram.O = block;
				pram.x0 = block.x;
				pram.y0 = block.y;
				ary.push(pram);

				cont.addChild(block);
			}
			addEventListener(Event.ENTER_FRAME, anime);
			screenHandler(null);
		}
		private function anime(e:Event):void {
			var len:int = ary.length;
			for (var i:int; i < len; i++) {
				var dx:Number = ary[i].O.parent.mouseX - ary[i].O.x;
				var dy:Number = ary[i].O.parent.mouseY - ary[i].O.y;
				var d:Number = Math.sqrt(dx * dx + dy * dy);
				ary[i].O.x = ary[i].O.x - _S / d * (dx / d) + (ary[i].x0 - ary[i].O.x) * _VS;
				ary[i].O.y = ary[i].O.y - _S / d * (dy / d) + (ary[i].y0 - ary[i].O.y) * _VS;
			}
		}
		private function screenHandler(e:Event):void {
			tf.y = stage.stageHeight - tf.height;
			cont.x = stage.stageWidth /2 - cont.width /2;
			cont.y = stage.stageHeight /2 - cont.height /2;
		}
		private function ran(max:int = 80):Number {
			var n:Number = Math.floor(Math.random() * max + 1);
			return n;
		}
		private function report() {
			tf.text = "W : " + String(W) + "\n" + "H : " + String(H) + "\n" + "TOTAL : " + String(W * H);
		}
		private function clickHandler(e:Event):void {
			var len:int = 0;
			len = ary.length;
			for (var i:int = 0; i < len; i++) {
				cont.removeChild(ary[0].O);
				ary.shift();
			}
			mX = ran(10);
			mY = ran(10);
			W = ran();
			H = ran();
			report();
			create(W, H);
		}
	}
}