Return to Snippet

Revision: 3261
at June 28, 2007 04:34 by mswallace


Initial Code
package {
	import flash.display.Sprite;
	import flash.events.MouseEvent;

	public class ExampleApplication extends Sprite{
		private var _sprite:Sprite;
				
		public function ExampleApplication(){
			_sprite = new Sprite();
			addChild(_sprite);
			_sprite.graphics.beginFill(0xFFFFFF);
			_sprite.graphics.drawRect(0, 0, 400, 400);
			_sprite.graphics.endFill();
			
			_sprite.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			_sprite.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
			
		}
		private function onMouseDown(event:MouseEvent):void{
			_sprite.graphics.lineStyle(1, 0, 1);
			_sprite.graphics.moveTo(mouseX, mouseY);
			_sprite.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
		}
		private function onMouseUp(event:MouseEvent):void{
			_sprite.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
		}
		private function onMouseMove(event:MouseEvent):void{
			_sprite.graphics.lineTo(mouseX, mouseY);
		}
	}
}

Initial URL

                                

Initial Description
This code will show you how to write Mouse Events using AS3 and also some simple Drawing API as well.

Initial Title
Mouse Events a simple drawing application using AS3

Initial Tags
actionscript, api, 3

Initial Language
ActionScript 3