FLASH矢量线条擦除:
/*
矢量线条的擦除在涂鸦板也许用处不是很大
写的不到位,还望高手指点
原理很简单,
用橡皮来检测与数组中的点相碰
删除碰撞点
重新绘制线条
放在第一帧就可以运行
Email:happyclub@163.com
*/
var startX:Number;
//起始点
var startY:Number;
var Path:MovieClip = this;
//路径
var lineArray:Array = [];
//鼠标点数组
var clearLine:Boolean = false;
//是否清除线条
var RdrawTo:Boolean = false;
//是否从新绘制
var StartDraw:Boolean = false;
//开始绘制
Path.createEmptyMovieClip("drawMc", 1);
//建绘图MC
Path.createEmptyMovieClip("mask", 2);
//建橡皮遮罩线条MC
var lineOrder:Number = 0;
//数组下标
//-----------------------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]);
}
}
}
//-------------------------重绘-----------------------------------------------------------
附件: FLASH矢量线条檫除.fla
附件: FLASH矢量线条檫除.swf