问题
I have a few radiobuttons I drag and drop within same group. In main.as I added click event listener.
How do I get the selected radiobutton ? handler target argument doesn't contain any reference to it.
回答1:
Grab a reference to the current RadioButtonGroup and access the selection reference, this will return a reference to the current radio button that is selected in the group.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/controls/RadioButtonGroup.html
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/controls/RadioButton.html#group
var rbg:RadioButtonGroup = RadioButton(e.currentTarget).group;
var selectedRadioButton:RadioButton = rbg.selection;
//Get the group name
trace(selectedRadioButton.groupName);
Alternatively you can just have your radio buttons in a compounded if statement like so:
if(radioButton1.selected == true){
}else if (radioButton2.selected == true){
}
回答2:
import fl.controls.RadioButton;
import fl.controls.RadioButtonGroup
var paymentGroup:RadioButtonGroup = new RadioButtonGroup("paymentOption");
rb1.group = paymentGroup;
rb2.group = paymentGroup;
paymentGroup.addEventListener(Event.CHANGE,handlerRbg);
function handlerRbg(e:Event):void
{
var rbg:RadioButtonGroup = e.target as RadioButtonGroup;
trace(rbg.selectedData);
}
来源:https://stackoverflow.com/questions/5532035/flash-radiobutton-how-do-i-get-the-selected-radiobutton