【问题标题】:Flex 3: Deselecting Toggle Button Through UIComponent ReferenceFlex 3:通过 UIComponent 参考取消选择切换按钮
【发布时间】:2011-05-04 05:11:02
【问题描述】:

我有一些将切换设置为 true 的按钮。我正在尝试将按钮的状态重新设置为未选中。但是,我不能像这样直接访问按钮:button.selected=false。

我正在访问 HBox 的子按钮,它们是按钮。 UIComonent 没有选定的属性。那么,如何取消选择下面这段代码中的切换?

for (var j : int=0; j < theHBox.numChildren; j++){
   var child : DisplayObject = theHBox.getChildAt(j);
   var myButton:UIComponent = child as UIComponent;
   myButton.setStyle("borderColor", "blue");
   myButton.visible = true;
   } 

【问题讨论】:

    标签: apache-flex button toggle uicomponents


    【解决方案1】:

    如果可能,我建议将 UIComponent 转换为按钮:

    for (var j : int=0; j < theHBox.numChildren; j++){
       var child : DisplayObject = theHBox.getChildAt(j);
       if(child is Button){
        var myButton:Button = child as Button;
        myButton.setStyle("borderColor", "blue");
        myButton.visible = true;
       } else if(child is somethingElse){
         // do something else
       }
    } 
    

    你也可以这样做:

    for (var j : int=0; j < theHBox.numChildren; j++){
       var child : DisplayObject = theHBox.getChildAt(j);
       var myButton:UIComponent = child as UIComponent;
       myButton.setStyle("borderColor", "blue");
       myButton.visible = true;
       myButton['toggle'] = false;
    } 
    

    如果所有子按钮都是按钮,这将起作用,但如果“myButton”没有切换属性,则会引发运行时错误。

    【讨论】:

    • 您好 Flextras.com,非常感谢您的帮助。我使用了选项 1。我能够摆脱 UIComponent。因此,我将行更改为 var myButton:Button = child as Button。我使用的其余代码未更改。再次感谢。
    • 很好地抓住了我的错字。当我在浏览器中编写代码时,有时会发生这种情况。我会在我的回答中修复它。很高兴为您提供帮助!
    猜你喜欢
    • 2017-12-01
    • 1970-01-01
    • 2021-02-23
    • 2019-02-14
    • 2021-10-15
    • 2017-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多