【问题标题】:How can I remove button I press in Flex?如何删除我在 Flex 中按下的按钮?
【发布时间】:2015-04-02 01:08:36
【问题描述】:

当我尝试这样做时,它不会删除右键。能否请您指出正确的方向以找出问题所在。

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
}

【问题讨论】:

  • 那么会发生什么,您希望发生什么,您尝试过什么解决方法?请提供一些细节
  • 感谢您的回复,
  • 感谢您的回复,我正在尝试删除我单击的按钮,例如:我添加了 3 个按钮 - b1、b2 和 b3。如果我使用 array.pop 并按 b1 ,则 b3 (最后一个)被删除。这不是我想要的,我想删除 b1。希望有意义...
  • help.adobe.com/en_US/AS2LCR/Flash_10.0/…Removes the last element from an array and returns the value of that element.。删除最后一个按钮有什么意外吗?

标签: arrays actionscript-3 apache-flex actionscript


【解决方案1】:

尝试关注。它将起作用并删除按下的按钮。

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

【讨论】:

  • 谢谢,工作正常,但最后一个按钮出错 Index-1 is out if range.我会尝试从这里开始。
  • 我做到了。在这里我没有收到错误。索引有问题。调试和检查。
  • 我的组件有问题..如果我跟踪数组 myArray.splice(myArray.indexOf(event.currentTarget), 1);获得按钮的正确位置 - 完美。但是当我使用另一行 myGroup.removeElementAt(myArray.indexOf(event.currentTarget));得到这个错误 RangeError: Index -1 is out of range.在 spark.components: 。谢谢。不要现在发生什么,我现在让你。
  • 再次感谢您的出色工作。问题是,我在 Hgroup 中有添加按钮。没有效果很好。
  • 按照我写答案的顺序使用这两行。 myGroup.removeElementAt(myArray.indexOf(event.currentTarget));是第一行和 myArray.splice(myArray.indexOf(event.currentTarget), 1);是第二个。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-05-20
  • 2020-11-08
  • 1970-01-01
  • 2017-09-29
  • 1970-01-01
  • 1970-01-01
  • 2019-09-28
相关资源
最近更新 更多