Posts Tagged ‘radio button’
Flex getting selected RadioButton value
Posted by: Stephen Gray on: 11 August, 2008
- In: Tutorials
- 14 Comments
This is a pretty simple one but there are surprisingly few tutorials showing the user simply how to get a selected RadioButtonGroup’s value.
There are quite a number of tutorials covering change event triggers for RadioButton controls but this is slightly different.
Say you have a form and you want to process the RadioButton value after submitting the form instead of when the value of it changes.
To do this you actually have to create a RadioButtonGroup MXML tag for the radio buttons and select the value using the ‘selectedValue’ property of that RadioButtonGroup:
<mx:RadioButtonGroup id="myRadioButtonGroup" enabled="true" />
<mx:RadioButton label="I like RadioButtons" groupName="{myRadioButtonGroup}" left="505" top="64" selected="true" value="true"/>
<mx:RadioButton label="I don't like RadioButtons" groupName="{myRadioButtonGroup}" left="348" top="62" value="false"/>
Notice the {} around the groupName attributes of the RadioButton controls. You can then do this to select the value:
Alert.show(myRadioButtonGroup.selectedValue.toString());