Flash radiobutton: how do I get the selected radiobutton?

醉酒当歌 提交于 2019-12-24 02:49:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!