2011-06-18 7 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} 
} 

私はすべてのボタンに対してクリックイベント時にマウスの位置を確認して、クリックされた1考え出すような愚かな何かを除いて、Flashでこれを行う方法を把握することはできません。

答えて

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

これはまさに私が探していたものです。ありがとう。 –

関連する問題