flex动态单选按钮,如何获取选定单选按钮的值

发布于 2024-10-10 00:23:32 字数 530 浏览 0 评论 0原文

我正在创建像这样的动态单选按钮,

for(var i:Number=0;i<xml.loc.length();i++)
{
    var radioBtn:RadioButton=new RadioButton();
    radioBtn.x=150;
    radioBtn.y=150;
    radioBtn.label=xml.loc[i];
    countryChoice.addChild(radioBtn);
    radioBtn.addEventListener(MouseEvent.CLICK,radiobuttonclickhandler)

    function radiobuttonclickhandler(event:MouseEvent):void
    {
        //here i need to get the selected radio button value.
         lblname.text=radioBtn.label
    }
}

我需要获取我选择的标签名称的值。该怎么做?

I am creating dynamic radion button like this

for(var i:Number=0;i<xml.loc.length();i++)
{
    var radioBtn:RadioButton=new RadioButton();
    radioBtn.x=150;
    radioBtn.y=150;
    radioBtn.label=xml.loc[i];
    countryChoice.addChild(radioBtn);
    radioBtn.addEventListener(MouseEvent.CLICK,radiobuttonclickhandler)

    function radiobuttonclickhandler(event:MouseEvent):void
    {
        //here i need to get the selected radio button value.
         lblname.text=radioBtn.label
    }
}

i need to get the value of labelname in which one is i am selected.how to do?

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

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

发布评论

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

评论(2

〃温暖了心ぐ 2024-10-17 00:23:32

不要使用groupName,而是使用group来一起设置radioButton。

group 是一个包含 RadioButtonGroup 对象的属性。这个对象可以知道哪个
RadioButton 通过使用 selection 属性进行选择。

Dont'use groupName, but group to set radioButton together.

group is a property which contains a RadioButtonGroup object. This object can know which
RadioButton is selected by using selection property.

青朷 2024-10-17 00:23:32

在您的循环中将单选按钮添加到单选按钮组。
在“for”循环之后,您将得到如下内容:
(设置与ragiobuttongroup id相同的groupName!)

 <mx:RadioButtonGroup
        id="radiobuttongroupname"/>
      <mx:RadioButton groupName="radiobuttongroupname" 
                      fontSize="7"
                      scaleX="2"
                      scaleY="2"
                      id="id1"
                      label="label1" 
                      width="100%"/>
      <mx:RadioButton groupName="radiobuttongroupname" 
                      fontSize="7"
                      scaleX="2"
                      scaleY="2"
                      id="id2"
                      label="label2" 
                      width="100%"/>
      <mx:RadioButton groupName="radiobuttongroupname" 
                      fontSize="7"
                      scaleX="2"
                      scaleY="2"
                      id="id3"
                      label="label3" 
                      width="100%"/>        
      <mx:RadioButton groupName="radiobuttongroupname" 
                      fontSize="7"
                      scaleX="2"
                      scaleY="2"
                      id="id4"
                      label="label4" 
                      width="100%"/>

现在您可以这样做:

radiobuttongroupname.selection.label

In your cycle add radio button to a radiobutton group.
After your "for" cycle you will have something like this:
(set the same groupName as ragiobuttongroup id!)

 <mx:RadioButtonGroup
        id="radiobuttongroupname"/>
      <mx:RadioButton groupName="radiobuttongroupname" 
                      fontSize="7"
                      scaleX="2"
                      scaleY="2"
                      id="id1"
                      label="label1" 
                      width="100%"/>
      <mx:RadioButton groupName="radiobuttongroupname" 
                      fontSize="7"
                      scaleX="2"
                      scaleY="2"
                      id="id2"
                      label="label2" 
                      width="100%"/>
      <mx:RadioButton groupName="radiobuttongroupname" 
                      fontSize="7"
                      scaleX="2"
                      scaleY="2"
                      id="id3"
                      label="label3" 
                      width="100%"/>        
      <mx:RadioButton groupName="radiobuttongroupname" 
                      fontSize="7"
                      scaleX="2"
                      scaleY="2"
                      id="id4"
                      label="label4" 
                      width="100%"/>

Now you can do that:

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