I have Flex code which is having radio button group declared in the fx:declaration section, which is to be used for non-gui components.
<fx:Declarations>
<s:RadioButtonGroup id="rdbtnlan"/>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
What is the purpose of doing this? The buttons are being used as follows:
protected function rdbtn1_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
if(rdbtnlan.selection.value == "Eng")
var dbResult:SQLResult = sqlcon.SQLCon("Update setting Set Language ='Eng'");
else if(rdbtnlan.selection.value == "Hindi")
var dbResult:SQLResult = sqlcon.SQLCon("Update setting Set Language ='Hindi'");
init();
}
Also the buttons refer to the radio button group in their tags:
<s:VGroup x="241" y="366" horizontalAlign="left" styleName="tabStyle" layoutDirection="ltr" id="rdbtn1">
<s:RadioButton id="rdSetEng" label="English" color="Black" groupName="rdbtnlan"
value="Eng" click="rdbtn1_clickHandler(event)"/>
<s:RadioButton id="rdSetHindi" label="Hindi" color="Black" groupName="rdbtnlan"
value="Hindi" click="rdbtn1_clickHandler(event)"/>
</s:VGroup>
As the documentation states:
The RadioButtonGroup component defines a group of RadioButton components that act as a single mutually exclusive component; therefore, a user can select only one RadioButton component at a time.
Note that your code snippet includes:
if(rdbtnlan.selection.value == "Eng")
rdbtnlan
is the button group, not a reference to a particular button. You're asking "What is the value selected for this group of buttons?"
Without the button group, you'd need to iterate through all the buttons in your component and check them individually, e.g.
if (rdSetEng.selected) {
var dbResult:SQLResult // ...
else if (rdSetHindi.selected) {
var dbResult:SQLResult // ...
}
Also note that you'd have no guarantees that rdSetEng
and rdSetHindi
were not both checked -- you'd have to write logic to deselect the other radio buttons in each button's click
handler.