How to get the label of the selected radio button in the event handler in Flex?
I have the following codes,
for (i=0; i<answerArray.length; i++) {
var myOptionButton1:spark.components.RadioButton = new spark.components.RadioButton();
myOptionButton1.label = answerArray.getItemAt(i).Answer_Choice;
if (answerArray.getItemAt(i).Correct_Flag == 1) {
myOptionButton1.value = 1;
} else {
myOptionButton1.value = 0;
}
answerItem.addChild(myOptionButton1);
myOptionButton1.group = rbGroup;
}
rbGroup.addEventListener(Event.CHANGE, selectionHandler);
}
rbGroup is the radio button group that holds the radio buttons together. Usually, there would be four radio buttons in this radio button group. In my selectionHandler function, for now, I am only trying to display the label of the selected radio button. event.currentTarget.label seems to be only working for checkboxes. Is there a way to get the label of the selected radio but开发者_JAVA百科ton?
Thanks in advance, Monte
Have look at the reference,
rbGroup.selection.label
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/components/RadioButtonGroup.html#selection
cheers,
From FlexExamples:
You could add a listener for the itemClick
event and access the event.Label
property.
<mx:RadioButtonGroup id="radioGroup" itemClick="radioGroup_itemClick(event);" />
private function radioGroup_itemClick(evt:ItemClickEvent):void {
trace(evt.label);
}
精彩评论