AS3涂鸦板

as3如下:

package { import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent;//import MouseEvent 包 [SWF(height = "450", width = "600", backgroundColor = "0xFFFFFF", frameRate = "40")] //设置应用程序属性 public class Main extends Sprite { public function Main():void { if (stage) { Init(); } else { addEventListener(Event.ADDED_TO_STAGE, Init); } } private function Init(e:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, Init); // entry point addEventListener(Event.ENTER_FRAME, OnEnterFrameHandler);//监听ENTER_FRAME事件,一个重要的事件 } private function OnEnterFrameHandler(e:Event):void { this.DrawGraphic(); } private function DrawGraphic():void { this.stage.addEventListener(MouseEvent.MOUSE_DOWN, OnMouseDownHandler);//监听鼠标Down事件 } private function OnMouseDownHandler(e:MouseEvent):void { this.graphics.lineStyle(2, 0, 1); this.graphics.moveTo(this.mouseX, this.mouseY); this.stage.addEventListener(MouseEvent.MOUSE_MOVE, OnMouseMoveHandler);//监听鼠标MOVE事件 } private function OnMouseMoveHandler(e:MouseEvent):void { this.graphics.lineTo(this.mouseX, this.mouseY); this.stage.addEventListener(MouseEvent.MOUSE_UP, OnMouseUpHandler);//监听鼠标UP事件 } private function OnMouseUpHandler(e:MouseEvent):void {// 移除对鼠标DOWN、MOVE和UP事件的监听 this.stage.removeEventListener(MouseEvent.MOUSE_DOWN, OnMouseDownHandler); this.stage.removeEventListener(MouseEvent.MOUSE_MOVE, OnMouseMoveHandler); this.stage.removeEventListener(MouseEvent.MOUSE_UP, OnMouseUpHandler); } } }

你可能感兴趣的:(Actionscript)