0
Im新的動作。如何檢查按鈕是否存在或不在動作。我想使用removechildname函數,嘗試它沒有成功。請幫助我。如何檢查按鈕是否存在或沒有在動作
Im新的動作。如何檢查按鈕是否存在或不在動作。我想使用removechildname函數,嘗試它沒有成功。請幫助我。如何檢查按鈕是否存在或沒有在動作
也許這樣的事情會幫助你:
// Since you have a array with names, i think you can do this:
// Get the length
var lengthOfButtonsNamesArray:int = buttonsNamesArray.length;
// looop through your array of names
for(var index:int = 0; index < lengthOfButtonsNamesArray; ++index){
// getting the button inside your buttons container using the array of names and getChildByName Method
var button:DisplayObject = buttonsContainer.getChildByName(buttonsNamesArray[index]) as DisplayObject;
// if the button was found
if(button != null){
// remove it
buttonsContainer.removeChild(button);
}
}
///////////////////////
// OR
//////////////////////
// If you are sure that there are only buttons inside your buttons container and you want to remove all of them
// Check the amount of children inside your buttons container
// while its greater then zero, remove the child at index of zero
while(buttonsContainer.numChildren > 0){
buttonsContainer.removeChildAt(0);
}
我沒有測試,但我敢肯定,這個工作的,反正讓我知道你是如何做什麼。
使用contains():
if (this.contains(myButton))
{
// then we know myButton exists inside of this class
this.removeChild(myButton); // removeElement(), in some situations
}
if (myDisplayContainer.contains(myButton))
{
// then we know myButton exists inside of myDisplayContainer
myDisplayContainer.removeChild(myButton); // removeElement(), in some
// situations
}
你能否提供更多信息?你知道按鈕ID,它是父母嗎?你想達到什麼,因爲這似乎是一個奇怪的問題,你應該有?你可以使用try-catch作爲parent.button,看看它是否有效 – simion314
什麼意思是「存在」?這是您放入顯示列表中的按鈕嗎?你是以編程方式(使用AS3)還是手動在Flash程序中創建此按鈕?您是否嘗試過:if(buttonName.stage){trace(「I exist!」)} else {trace(「I do not exist!」)} – Craig
該按鈕是動態創建的動態名稱屬性。我的問題是我有在到達提示點時播放的視頻im在視頻上生成幾個按鈕,並且im還將這些動態名稱值存儲在數組中並且在達到指定時間時在視頻進度上說出提示點發生後10秒,使用數組我需要刪除生成的button.Now – user3257881