2011-06-18 46 views
0

我需要一些關於如何用不同的事件處理程序以編程方式創建多個按鈕的指針,或者更確切地說:不同的參數化事件處理程序。我的真正用途有點複雜,但歸結起來就是:我需要一個可以在點擊時自行刪除的按鈕。Flash:動態按鈕點擊處理程序

var Buttons:Vector.<Button> = new Vector.<Button>;  
var newButton = new Button; 
var int = Buttons.push(newButton);    
newButton.addEventListener(MouseEvent.CLICK, button_clickHandler); 


// pseudocode 
button_clickHandler(event:MouseEvent):void { 
    if (event.button = i) { delete button i} 
} 

我想不出這樣做在Flash中,除了做一些愚蠢像對所有按鈕的Click事件過程中檢查鼠標的位置,然後找出被點擊其中一個方式。

回答

4

你可以做別的事情,但類似:

private function buttonClickHandler(event:MouseEvent):void 
{ 
     var button:Button = Button(event.target); 
     var i:int = buttons.indexOf(button); 
     // now you know the button instance and the index of the button so do whatever you need 

     // delete it from the vector: 
     buttons.splice(i, 1); 
} 

你或許應該從舞臺上太,雖然將其刪除。

+0

這正是我所期待的。謝謝。 –