我不明白为什么我的显示对象没有被删除。当我按下按钮,我希望能够获得形状和按键的跟踪和去除,但没有任何反应:Actionscript删除显示对象
import fl.controls.Button;
var shape1:Shape = new Shape();
shape1.name = "Shape1";
shape1.graphics.lineStyle(4, 0x000000);
shape1.graphics.beginFill(0x000055, 0.5);
shape1.graphics.drawRoundRect(50, 50, 100, 75, 20, 30);
shape1.graphics.endFill();
addChild(shape1);
var shape2:Shape = new Shape();
shape2.name = "Shape2";
shape2.graphics.lineStyle(4, 0xFFFF99);
shape2.graphics.beginFill(0x550000, 0.5);
shape2.graphics.drawRoundRect(100, 75, 200, 175, 50, 10);
shape2.graphics.endFill();
addChild(shape2);
button1.addEventListener(MouseEvent.CLICK, pushButton);
function pushButton(evt:MouseEvent):void
{
for(var amount:int = numChildren; amount == 0; amount--)
{
trace(amount);
var disObj:DisplayObject = getChildAt(amount);
trace("Removing " + disObj.name);
removeChildAt(amount);
}
}
我知道有实现这一点有更好的方法,但我学习,所以只感兴趣的是为什么上面的代码不起作用。
感谢。 – TheDarkIn1978 2010-03-19 22:23:18