已经使用以下代码(在函数内)在点之间创建线。我需要使用按钮清除这些线。
var v = 0;
function getLocation(a,b,c,d,e)
{
if (v>0)
{
var line1:MovieClip = new MovieClip();
line1.graphics.lineStyle(2,0x00CCFF);
line1.graphics.moveTo(a,b);
line1.graphics.lineTo(c,d);
this.addChild(line1);
}
else
{
v++;
var line2:MovieClip = new MovieClip();
line2.graphics.lineStyle(2,0x00CCFF);
line2.graphics.moveTo(a,b);
line2.graphics.lineTo(mouseX,mouseY);
this.addChild(line2);
}
}
答案 0 :(得分:0)
如何使用数组。
var v = 0;
var arr: Array = new Array();
function getLocation(a,b,c,d,e)
{
if (v>0)
{
var line1:MovieClip = new MovieClip();
line1.graphics.lineStyle(2,0x00CCFF);
line1.graphics.moveTo(a,b);
line1.graphics.lineTo(c,d);
arr.push(line1);
this.addChild(line1);
}
else
{
v++;
var line2:MovieClip = new MovieClip();
line2.graphics.lineStyle(2,0x00CCFF);
line2.graphics.moveTo(a,b);
line2.graphics.lineTo(mouseX,mouseY);
arr.push(line2);
this.addChild(line2);
}
}
function removeLine(): void
{
if (arr.length != 0) {
var mc:MovieClip = arr.pop();
this.removeChild(mc);
}
}
答案 1 :(得分:0)
一个简单的解决方案是为movieclip提供实例名称,然后稍后将其清除
var v:Number = 0;
var line:MovieClip;
function getLocation(a,b,c,d,e)
{
if(line==null)
{
line = new MovieClip;
addChild(line);
}
else
{
line.graphics.clear();
}
line.graphics.lineStyle(2,0x00CCFF);
line.graphics.moveTo(a,b);
if (v>0)
{
line.graphics.lineTo(c,d);
}
else
{
v++;
line.graphics.lineTo(mouseX,mouseY);
}
}
//It can be cleared from here as well
function onButtonClickHandler(e:MouseEvent)
{
if(line)
{
line.graphics.clear();
}
}
除非您有特殊要求,否则我建议您使用以下内容
{{1}}
答案 2 :(得分:0)
将所有行放入容器中:
var lines:Sprite = new Sprite();
addChild(lines);
function getLocation(a, b, c, d) {
// ...
lines.addChild(line);
}
然后删除它们使用:
lines.removeChildren();