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

Drawing

Get Adobe Flash player
by mook 07 Nov 2009
/**
 * Copyright mook ( http://wonderfl.net/user/mook )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/Aoif
 */

package {
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;

	public class Drawing extends Sprite {
		public var myFlag:Boolean;
		
		public function Drawing() {
			//textField
			var text:TextField = new TextField;
			text.width = 200;
			text.text = 'Drag and draw the line.';
			text.x = 20;
			text.y = 20;
			this.addChild(text);
			
			stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
			stage.addEventListener(MouseEvent.MOUSE_UP, mouseUp);
		    this.addEventListener(Event.ENTER_FRAME, enterFrame);
		}
		
		public function mouseDown(e:MouseEvent):void {
			myFlag = true;
		}
		
		public function mouseUp(e:MouseEvent):void {
			myFlag = false;
		}
		
		public function drawLine(e:MouseEvent):void {
			var circle:Shape = new Shape();
			var myX:int = mouseX - 10;
			var myY:int = mouseY - 10;
			circle.graphics.beginFill(0xff0000, 1);
			circle.graphics.drawCircle(myX, myY, 20);
			addChild(circle);
		}
		
		public function enterFrame(e:Event):void {
			if(myFlag == true) {
                stage.addEventListener(MouseEvent.MOUSE_MOVE, drawLine);
            } else {
                stage.removeEventListener(MouseEvent.MOUSE_MOVE, drawLine);
            }
		}
	}
}