我在Flash中製作遊戲,並使用陣列動態創建項目並將其放置在庫存中。 LongSword是一個MovieClip。我把影片剪輯數組中像這樣:AS3:如何刪除通過數組創建並放置在舞臺上的MovieClip?
function buyitem1(e:Event):void
{
if(Store.itemslot.length < 6 && Store.currentMenu == 1 &&score >= 450)
{
Store.itemslot.push(new LongSword);
}
}
現在我想要當長劍爲「出售」,從舞臺中刪除影片剪輯。我怎樣才能刪除這個長劍?我已經試過:
for(var i:int = 0; i < Store.itemslot.length; i++)
{
if(Store.itemslot[i] == LongSword)
{
stage.removeChild(Store.itemslot[0]);
}
}
香港專業教育學院也嘗試:
for(var i:int = 0; i < Store.itemslot.length; i++)
{
if(Store.itemslot[i] == new LongSword)
{
stage.removeChild(Store.itemslot);
}
}
和幾個變化。有任何想法嗎?
請考慮使用常數,而不是簡單的數字。單身人士可以幫助你獲得「當前遊戲狀態」的價值。 – 2012-02-17 23:38:34