as3.0 橡皮功能2
Posted zqiang0803
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了as3.0 橡皮功能2相关的知识,希望对你有一定的参考价值。
package com{ import flash.display.MovieClip; import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.SimpleButton; import flash.events.MouseEvent; import flash.display.Shape; import flash.geom.Matrix; import flash.geom.ColorTransform; import flash.geom.Rectangle; import flash.display.BlendMode; public class Drow extends MovieClip { private var emptyMc:MovieClip; private var bitmap:Bitmap; private var bitmapD:BitmapData; private var blackboard:MovieClip; private var thisMc:MovieClip; private var shape:Shape; private var newMcArr:Array=[]; private var newMc:MovieClip; public function Drow(_emptyMc:MovieClip,_thisMc:MovieClip,_blackboard:MovieClip) { emptyMc=_emptyMc; thisMc=_thisMc; blackboard=_blackboard; shape=new Shape() ; bitmapD=new BitmapData(blackboard.width,blackboard.height,true,0); bitmap=new Bitmap(bitmapD,"auto",true); emptyMc.addChild(bitmap); } 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) { penBtn.visible=false; blackboard.addEventListener(MouseEvent.MOUSE_DOWN,downFun); } else { penBtn.visible=true; blackboard.removeEventListener(MouseEvent.MOUSE_DOWN,downFun); } } else if (str=="revokeBtn") { trace(emptyMc.numChildren); emptyMc.removeChildAt(emptyMc.numChildren-1); } else if (str=="eraserBtn") { if (eraserBtn.visible==true) { eraserBtn.visible=false; penBtn.visible=true; } else { eraserBtn.visible=true; } } } private function downFun(e:MouseEvent) { shape.graphics.lineStyle(20,0); 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); if (eraserBtn.visible==false) { bitmapD.draw(shape,new Matrix(),new ColorTransform(),BlendMode.ERASE); } if (penBtn.visible==false) { bitmapD.draw(shape,new Matrix(),new ColorTransform(),BlendMode.NORMAL,new Rectangle(0,0,1920,1080)); } e.updateAfterEvent(); } private function upFun(e:MouseEvent) { shape.graphics.clear(); blackboard.removeEventListener(MouseEvent.MOUSE_MOVE,moveFun); blackboard.removeEventListener(MouseEvent.MOUSE_UP,upFun); } } }
以上是关于as3.0 橡皮功能2的主要内容,如果未能解决你的问题,请参考以下文章