制作涂鸦板
var drawing:Boolean; Mouse.hide(); //隐藏默认的光标 stage.addEventListener(MouseEvent.MOUSE_MOVE,Stage_MouseMove); stage.addEventListener(MouseEvent.MOUSE_DOWN,Stage_MouseDown); stage.addEventListener(MouseEvent.MOUSE_UP,Stage_MouseUp); stage.addEventListener(KeyboardEvent.KEY_DOWN,Stage_KeyDown); function Stage_MouseDown(e:MouseEvent):void { this.graphics.moveTo(this.mouseX,this.mouseY);//设置划线的起点 this.graphics.lineStyle(3,0x99cc00,100);//设置笔触大小及颜色 drawing=true; } function Stage_MouseMove(e:MouseEvent):void { //铅笔鼠标跟随 pen1.x=this.mouseX; pen1.y=this.mouseY; if (drawing) { this.graphics.lineTo(this.mouseX,this.mouseY);//关键代码就在这里 } e.updateAfterEvent(); } function Stage_MouseUp(e:MouseEvent):void { drawing=false; } function Stage_KeyDown(e:KeyboardEvent):void { if (e.keyCode==Keyboard.DELETE) { //注意这里:虽然代码只写了Delete键,但实际测试中发现如果按Ctrl + Delete组合键,也能触发 this.graphics.clear(); } }