as3.0 橡皮功能


import flash.display.Bitmap;
import flash.display.BitmapData;

//主容器
var main:Sprite = new Sprite();
main.mouseEnabled=false;
addChild(main);
//临时容器(所有操作都将先画在临时容器里,再进行"画"或"擦")
var mc:Sprite = new Sprite();
main.addChild(mc);
//保存最终画出来的内容的bitmapdata;
var content:BitmapData=new BitmapData(1920,1080,true,0x00FFFFFF);
//把content显示出来
var show:Bitmap=new Bitmap(content,"auto",true);
main.addChildAt(show,0);

//默认选中画笔
var action:Number=0;
txt.text="当前选中:画笔";


mc_move.addEventListener(MouseEvent.MOUSE_DOWN,startDraw);
a.addEventListener(MouseEvent.CLICK,changeAction);
b.addEventListener(MouseEvent.CLICK,changeAction);
function changeAction(e:MouseEvent):void {
if (e.target.name=="a") {
action=0;
txt.text="当前选中:画笔";
mc.visible=true;
} else {
action=1;
txt.text="当前选中:橡皮";
mc.visible=false;
}
}
function startDraw(e:MouseEvent):void {
mc.graphics.lineStyle(20,cp.selectedColor);
//cp是颜色组件的实例名
mc.graphics.moveTo(mouseX,mouseY);
mc_move.addEventListener(MouseEvent.MOUSE_MOVE,drawing);
//mc_move可以理解成画板
stage.addEventListener(MouseEvent.MOUSE_UP,stopDraw);
}
function stopDraw(e:MouseEvent):void {
if (action!=1) {
content.draw(mc,new Matrix(),new ColorTransform(),BlendMode.NORMAL,new Rectangle(0,0,1920,1080));
}
mc.graphics.clear();
mc_move.removeEventListener(MouseEvent.MOUSE_MOVE,drawing);
stage.removeEventListener(MouseEvent.MOUSE_UP,stopDraw);
}
function drawing(e:MouseEvent):void {
mc.graphics.lineTo(mouseX,mouseY);
if (action==1) {
content.draw(mc,new Matrix(),new ColorTransform(),BlendMode.ERASE);
}
e.updateAfterEvent();
}

import flash.display.Bitmap;
import flash.display.BitmapData;

//主容器
var main:Sprite = new Sprite();
main.mouseEnabled=false;
addChild(main);
//临时容器(所有操作都将先画在临时容器里,再进行"画"或"擦")
var mc:Sprite = new Sprite();
main.addChild(mc);
//保存最终画出来的内容的bitmapdata;
var content:BitmapData=new BitmapData(1920,1080,true,0x00FFFFFF);
//把content显示出来
var show:Bitmap=new Bitmap(content,"auto",true);
main.addChildAt(show,0);

//默认选中画笔
var action:Number=0;
txt.text="当前选中:画笔";


mc_move.addEventListener(MouseEvent.MOUSE_DOWN,startDraw);
a.addEventListener(MouseEvent.CLICK,changeAction);
b.addEventListener(MouseEvent.CLICK,changeAction);
function changeAction(e:MouseEvent):void {
    if (e.target.name=="a") {
        action=0;
        txt.text="当前选中:画笔";
        mc.visible=true;
    } else {
        action=1;
        txt.text="当前选中:橡皮";
        mc.visible=false;
    }
}
function startDraw(e:MouseEvent):void {
    mc.graphics.lineStyle(20,cp.selectedColor);
    //cp是颜色组件的实例名
    mc.graphics.moveTo(mouseX,mouseY);
    mc_move.addEventListener(MouseEvent.MOUSE_MOVE,drawing);
    //mc_move可以理解成画板
    stage.addEventListener(MouseEvent.MOUSE_UP,stopDraw);
}
function stopDraw(e:MouseEvent):void {
    if (action!=1) {
        content.draw(mc,new Matrix(),new ColorTransform(),BlendMode.NORMAL,new Rectangle(0,0,1920,1080));
    }
    mc.graphics.clear();
    mc_move.removeEventListener(MouseEvent.MOUSE_MOVE,drawing);
    stage.removeEventListener(MouseEvent.MOUSE_UP,stopDraw);
}
function drawing(e:MouseEvent):void {
    mc.graphics.lineTo(mouseX,mouseY);
    if (action==1) {
        content.draw(mc,new Matrix(),new ColorTransform(),BlendMode.ERASE);
    }
    e.updateAfterEvent();
}

 

posted on 2018-08-06 10:17  zqiang0803  阅读(124)  评论(0编辑  收藏  举报

导航