Flex 3:通过 UIComponent 参考取消选择切换按钮

发布于 2024-09-30 19:56:28 字数 418 浏览 3 评论 0原文

我有一些按钮的切换设置为 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;
   } 

I've got some buttons that have toggle set to true. I'm trying to re-set the button's state to unselected. But, I can't access the button directly like: button.selected=false.

I'm accessing the HBox's children which are the buttons. UIComonent doesn't have a selected property. So, how do I de-select the toggle in this bit of code below?

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;
   } 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗心遗梦遗幸福 2024-10-07 19:56:28

如果可能,我建议将 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”没有切换属性,则会引发运行时错误。

If possible, I would recommend casting the UIComponent to a button:

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
   }
} 

You could also do something like this:

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;
} 

Which will work if all children are buttons, but if the 'myButton' does not have a toggle property, it will throw a run time error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文