如何删除我在Flex中按下的按钮?

时间:2015-02-02 23:24:58

标签: arrays actionscript-3 flex actionscript

当我尝试这个时,它不会删除右键。能不能指出我找到错误的正确方向。

private var myArray:Array = [];
private var myButton:Button;
public function addButton():void {
var i:uint = myArray.length;
                myButton = new Button();
                myButton.label = "New Button"+ String(i);
                myButton.id= "myButton" + String(i);
                myGroup.addElement(myButton);
                myArray.push(myGroup.addElement(myButton));
                myButton.addEventListener(MouseEvent.CLICK, removeButton);
            }
public function removeButton(event:MouseEvent):void {
//myGroup.removeElement(myArray.splice(2,1)); don´t work
//myGroup.removeElement(myArray.pop()); remove the last one
}

1 个答案:

答案 0 :(得分:0)

试试以下内容。它将起作用并移除按下的按钮。

public function removeButton(event:MouseEvent):void 
{
    myGroup.removeElementAt(myArray.indexOf(event.currentTarget));
    myArray.splice(myArray.indexOf(event.currentTarget), 1); 
}
相关问题