aravinda
aravinda

Reputation: 71

flex dynamic radio button,how to get the value of selected radio button

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?

Upvotes: 1

Views: 2932

Answers (2)

ivy
ivy

Reputation: 210

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

Upvotes: 0

Epharion
Epharion

Reputation: 1071

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.

Upvotes: 1

Related Questions