如何删除我在 Flex 中按下的按钮?
How can I remove button I press in Flex?
当我尝试此操作时,它没有删除右键。能否请您指出正确的方向以找出问题所在。
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
}
试试看。它会起作用并移除按下的按钮。
public function removeButton(event:MouseEvent):void
{
myGroup.removeElementAt(myArray.indexOf(event.currentTarget));
myArray.splice(myArray.indexOf(event.currentTarget), 1);
}
当我尝试此操作时,它没有删除右键。能否请您指出正确的方向以找出问题所在。
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
}
试试看。它会起作用并移除按下的按钮。
public function removeButton(event:MouseEvent):void
{
myGroup.removeElementAt(myArray.indexOf(event.currentTarget));
myArray.splice(myArray.indexOf(event.currentTarget), 1);
}