我不明白爲什麼我的顯示對象沒有被刪除。當我按下按鈕,我希望能夠獲得形狀和按鍵的跟蹤和去除,但沒有任何反應: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