package com{
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.display.Shape;
import flash.geom.ColorTransform;
import flash.geom.Rectangle; public class Drow extends MovieClip { private var emptyMc:MovieClip;
private var blackboard:MovieClip;
private var thisMc:MovieClip;
private var shape:Shape;
private var colorNum:Number
public function Drow(_emptyMc:MovieClip,_thisMc:MovieClip,_blackboard:MovieClip) {
emptyMc=_emptyMc;
thisMc=_thisMc;
blackboard=_blackboard;
}
private var penBtn:SimpleButton;
private var revokeBtn:SimpleButton;
private var eraserBtn:SimpleButton;
public function toolFun(_penBtn:SimpleButton,_revokeBtn:SimpleButton,_eraserBtn:SimpleButton) {
penBtn=_penBtn;
revokeBtn=_revokeBtn;
eraserBtn=_eraserBtn;
eraserBtn.addEventListener(MouseEvent.CLICK,onClick);
revokeBtn.addEventListener(MouseEvent.CLICK,onClick);
penBtn.addEventListener(MouseEvent.CLICK,onClick);
}
private function onClick(e:MouseEvent) { var str:String=e.target.name;
if (str=="penBtn") {
if (penBtn.visible==true) {
colorNum=0
penBtn.visible=false;
blackboard.addEventListener(MouseEvent.MOUSE_DOWN,downFun);
} else {
penBtn.visible=true;
blackboard.removeEventListener(MouseEvent.MOUSE_DOWN,downFun);
}
} else if (str=="revokeBtn") {
if(emptyMc.numChildren-1>=0)
emptyMc.removeChildAt(emptyMc.numChildren-1);
} else if (str=="eraserBtn") {
if (eraserBtn.visible==true) {
eraserBtn.visible=false;
penBtn.visible=true;
colorNum=0xFFFFFF
} else {
eraserBtn.visible=true;
}
} }
private function downFun(e:MouseEvent) { shape=new Shape()
emptyMc.addChild(shape)
shape.graphics.clear();
shape.graphics.lineStyle(5,colorNum);
shape.graphics.moveTo(mouseX,mouseY);
blackboard.addEventListener(MouseEvent.MOUSE_MOVE,moveFun);
blackboard.addEventListener(MouseEvent.MOUSE_UP,upFun);
}
private function moveFun(e:MouseEvent) {
shape.graphics.lineTo(mouseX,mouseY);
e.updateAfterEvent();
}
private function upFun(e:MouseEvent) {
blackboard.removeEventListener(MouseEvent.MOUSE_MOVE,moveFun);
blackboard.removeEventListener(MouseEvent.MOUSE_UP,upFun);
} } }