First look at the effect (first with the mouse to draw, and then you can use the Blue block erase)
Click here to download the source file
Flash Vector Line Erase:
/*
The erasure of vector lines may not be very useful in the graffiti board
Write not in place, but also hope that the master pointing
The principle is simple,
To detect a point in an array with an eraser
Delete Collision Point
Redraw lines
You can run it on the first frame.
Email:happyclub@163.com
*/
var Startx:number;
Starting point
var Starty:number;
var path:movieclip = this;
Path
var linearray:array = [];
Group of Mouse points
var Clearline:boolean = false;
Whether to clear lines
var Rdrawto:boolean = false;
Whether to paint new
var Startdraw:boolean = false;
Start drawing
Path.createemptymovieclip ("DRAWMC", 1);
Building a drawing MC
Path.createemptymovieclip ("Mask", 2);
Building a rubber Mask line MC
var lineorder:number = 0;
Array subscript
-----------------------INIT-------------------------------------
var eraser:movieclip = Createrectangle (15, 15);
eraser._x = STAGE.WIDTH/2;
eraser._y = STAGE.HEIGHT/2;
eraser.onpress = function () {
Clearline = true;
This.startdrag ();
};
Eraser.onrelease = function () {
Clearline = false;
Stopdrag ();
};
function Createrectangle (W, H): MovieClip {
var depth:number = path.getnexthighestdepth ();
var mc:movieclip = path.createemptymovieclip ("eraser", depth);
Mc.beginfill (0X0033FF);
Mc.lineto (0, H);
Mc.lineto (W, H);
Mc.lineto (W, 0);
Mc.lineto (0, 0);
return MC;
}
--------------------------Eraser------------------------------------
Path.onmousedown = function () {
var i = 0;
while (Linearray = = "#") {
i++;
}
Linearray.splice (0, I);
Lineorder = Linearray.length;
Startdraw = true;
StartX = _xmouse;
Starty = _ymouse;
Insertion = true;
};
Path.onmousemove = function () {
if (Startdraw = = True && Clearline = = False) {
Linearray[lineorder] = [];
Linearray[lineorder].push (_xmouse, _ymouse);
Path.drawMc.lineStyle (5, 0, 100);
Path.drawMc.moveTo (StartX, starty);
Path.drawMc.lineTo (_xmouse, _ymouse);
lineorder++;
}
StartX = _xmouse;
Starty = _ymouse;
if (Clearline = = True) {
for (var i = 0; i<linearray.length; i++) {
if (Path.eraser.hitTest (linearray[0], linearray[1], true) {
Path.mask.lineStyle (5, 0XFFFFFF, 100);
Path.mask.moveTo (Linearray[0], linearray[1]);
Path.mask.lineTo (linearray[0]+1, linearray[1]+1);
Path.mask.lineTo (Linearray[0]-1, linearray[1]-1);
Insertion = = True && linearray[i-1]!= "#" && linearray!= "#" && linearray[i+1]!= "#"? (Linearray.splice (I, 1, "#")): Linearray.splice (I, 1);
Rdrawto = true;
insertion = false;
Break
}
}
}
};
-----------------------MOUSEMOVE------------------------------------
Path.onmouseup = function () {
Startdraw = false;
if (Rdrawto = = True) {
Rdraw ();
}
Linearray[linearray.length-1]!= "#"? (Linearray.push ("#"), lineorder++): null;
Rdrawto = false;
};
-----------------------MOUSEUP---------------------------------------
function Rdraw () {
Path.mask.clear ();
Path.drawMc.clear ();
Path.drawMc.lineStyle (5, 0, 100);
for (var i = 0; i<linearray.length; i++) {
if (linearray!= undefined && linearray[i+1]!= undefined && linearray[i+1]!= "#" && Linearray!= "#") {
Path.drawMc.moveTo (Linearray[0], linearray[1]);
Path.drawMc.lineTo (Linearray[i+1][0], linearray[i+1][1]);
}
}
}
-------------------------Redraw----------------------------------------