目前,如果您单击您创建的框,它将删除该框,但会立即创建另一个框。我想在舞台上单击以创建一个框,然后单击该框以删除该框-仅此而已。
import flash.display.MovieClip;
import flash.events.*;
public class testcatnab extends MovieClip
{
public static var boxCount:int = 0;
var box = new Box();
public function testcatnab()
{
stage.addEventListener(MouseEvent.CLICK, clickOnStage);
box.addEventListener(MouseEvent.CLICK, clickOnBox);
}
function clickOnStage(e:MouseEvent)
{
box.x = mouseX;
box.y = mouseY;
addChild(box);
boxCount++;
trace(boxCount);
}
function clickOnBox(e:MouseEvent)
{
boxCount--;
removeChild(box);
trace(boxCount);
}
}
编辑 - 通过制作单独的背景影片剪辑并将其用作可点击对象来修复它