//
舞台上当前层需要放置名称分别为mc_bursh/mc_earse的影片剪辑
//
友情提示,例子中有跟界面呈现不相关的代码,不过不影响实际功能,具体使用的时候,可以考虑酌情删减!
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;
var tools = "bursh";
var widthh = 1200;
var base_point:Point = new Point(0, 0);
var base_rectangle:Rectangle = new Rectangle(0, 0, 25, 25);
var bit1:BitmapData = new BitmapData(widthh, 768,
false, 0xff0000);
var org_bit:BitmapData = new BitmapData(widthh, 768,
true, 0);
org_bit.draw(bit1);
var draw_bit:BitmapData = org_bit.clone();
createEmptyMovieClip("draw_mc", -999);
createEmptyMovieClip("mc1", 2);
createEmptyMovieClip("mc2", 3);
createEmptyMovieClip("mc3", 4);
drawCircle(mc1, 40, 40, 40, 0x000000);
drawCircle(mc2, 4, 4, 4, 0x000000);
mc1._visible = mc2._visible=mc3._visible=
false;
draw_mc.attachBitmap(draw_bit, 1);
var erase_bit:BitmapData = new BitmapData(mc1._width, mc1._height,
true, 0);
var redraw_bit:BitmapData = new BitmapData(mc2._width, mc2._height,
true, 0);
erase_bit.fillRect(erase_bit.rectangle, 0xFFFFFFFF);
erase_bit.draw(mc1);
redraw_bit.draw(mc2);
erase_bit.copyChannel(erase_bit, erase_bit.rectangle, new Point(0, 0), 1, 8);
var tools:
String;
earse_first();
mc_bursh.onRelease =
function() {
this.gotoAndStop(2);
mc_earse.gotoAndStop(1);
tools = "bursh";
};
mc_earse.onRelease =
function() {
this.gotoAndStop(2);
mc_bursh.gotoAndStop(1);
tools = "easre";
};
draw_mc.onPress =
function() {
if (tools == "bursh") {
trace(1);
mc3.moveTo(mc3._xmouse, mc3._ymouse);
this.onMouseMove = bursh_pic;
}
if (tools == "easre") {
this.onMouseMove = earse_pic;
}
};
draw_mc.onRelease = draw_mc.onReleaseOutside=
function () {
delete this.onMouseMove;
};
function earse_pic() {
mc3.clear();
var now_rect:Rectangle = new Rectangle(_xmouse-mc1._width/2, _ymouse-mc1._width/2, _xmouse+base_rectangle.width, _ymouse+base_rectangle.height);
draw_bit.copyPixels(draw_bit, now_rect, new Point(_xmouse-mc1._width/2, _ymouse-mc1._width/2), erase_bit, new Point(0, 0),
false);
updateAfterEvent();
}
function earse_first() {
var now_rect:Rectangle = new Rectangle(0, 0, widthh, 768);
draw_bit.copyPixels(draw_bit, now_rect, new Point(0, 0), new BitmapData(widthh, 768,
true, 0x0), new Point(0, 0),
false);
updateAfterEvent();
}
function bursh_pic() {
trace(mc3);
mc3.lineStyle(8, 0xff0000, 100);
mc3.lineTo(mc3._xmouse, mc3._ymouse);
draw_bit.draw(mc3);
draw_mc.attachBitmap(draw_bit, 1);
//
var now_rect:Rectangle = new Rectangle(_xmouse, _ymouse, _xmouse+base_rectangle.width, _ymouse+base_rectangle.height);
//
draw_bit.copyPixels(org_bit, now_rect, new Point(_xmouse-mc2._width/2, _ymouse-mc2._width/2), redraw_bit, new Point(0, 0), true);
//
updateAfterEvent();
}
function drawCircle(mc:
MovieClip, x:
Number, y:
Number, r:
Number, color:
Number):
Void {
mc.beginFill(color);
mc.moveTo(x+r, y);
mc.curveTo(r+x, Math.tan(Math.PI/8)*r+y, Math.sin(Math.PI/4)*r+x, Math.sin(Math.PI/4)*r+y);
mc.curveTo(Math.tan(Math.PI/8)*r+x, r+y, x, r+y);
mc.curveTo(-Math.tan(Math.PI/8)*r+x, r+y, -Math.sin(Math.PI/4)*r+x, Math.sin(Math.PI/4)*r+y);
mc.curveTo(-r+x, Math.tan(Math.PI/8)*r+y, -r+x, y);
mc.curveTo(-r+x, -Math.tan(Math.PI/8)*r+y, -Math.sin(Math.PI/4)*r+x, -Math.sin(Math.PI/4)*r+y);
mc.curveTo(-Math.tan(Math.PI/8)*r+x, -r+y, x, -r+y);
mc.curveTo(Math.tan(Math.PI/8)*r+x, -r+y, Math.sin(Math.PI/4)*r+x, -Math.sin(Math.PI/4)*r+y);
mc.curveTo(r+x, -Math.tan(Math.PI/8)*r+y, r+x, y);
mc.endFill();
}