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

SquareLines

package {
	import flash.display.*;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	public class SquareLines extends Sprite {
		private var _bmd:BitmapData;
		private var _prev:Point;
		private var _rect:Shape;
		private var _canvas:Sprite;
		public function SquareLines():void {
			_bmd = new BitmapData(465, 465);
			addChild(new Bitmap(_bmd));
			_canvas = new Sprite();
			_rect = new Shape();
			_canvas.addChild(_rect);
			stage.addEventListener(MouseEvent.MOUSE_MOVE, update);
			stage.addEventListener(Event.MOUSE_LEAVE, leave);
		}
		
		private function update(e:MouseEvent):void {
			if(_prev == null) _prev = new Point(mouseX, mouseY);
			var dx:Number = mouseX - _prev.x;
			var dy:Number = mouseY - _prev.y;
			var dis:Number = Math.sqrt(dx * dx + dy * dy);
			var rad:Number = Math.atan2(dy, dx) * 180 / Math.PI;
			_prev.x = mouseX;
			_prev.y = mouseY;
			
			_rect.graphics.clear();
			_rect.graphics.beginFill(0xffffff);
			_rect.graphics.lineStyle(0, 0x000000, 0.5);
			_rect.graphics.drawRect( -dis, -dis/4, dis, dis/2);
			_rect.rotation = rad;
			_rect.x = mouseX;
			_rect.y = mouseY;
			
			_bmd.draw(_canvas);		
		}
		
		private function leave(e:Event):void {
			_prev = null;
		}		
	}
}