Skip to main content
Known Participant
November 19, 2009
Answered

How to trap which radio button was selected and its data?

  • November 19, 2009
  • 1 reply
  • 1029 views

Good day everyone,

Need help on this one. This would be my first post regarding components, specifically radio button.

Here's goes my problem I have several groups of radio button. And I want to track which radio button on each group was selected, and I will get the data and pass it to a loadVariablesNum function.

Thanks,

Any help is very much appreciated.

This topic has been closed for replies.
Correct answer Ned Murphy

All the radio buttons is inside the movieclip "contents". And I get the undefined results after I select one of the radio button in the 1st group. And click on the button that triggers loadVariablesNum.

Thanks again,


You didn't answer my second question.  Is the button in the same timeline as the contents mc?  And now that you mention the buttons function, where are you using that code of mine that you said gives "undefined"?

It will be to your benefit to create a new file to resolve this where you simply have some radio buttons and another normal button that uses that blue code.  Once you have that working you should be able to adapt it into your scenario more easily.

1 reply

Ned Murphy
Legend
November 19, 2009

You can use the following to determine which radio within a group is selected and what the data is for that selection...

Selected Radio: radioGroup.selection
Selected Radio Data: radioGroup.selection.data

Known Participant
November 19, 2009

Thank you for replying Sir NedWebs,

The structure of my application is that all of my radio button is inside a movieclip called "contents". And each row has 4 radio button belong to a group, do I have to make an instance name on each of the radio button?

And I have a button that will trigger loadVariablesNum on each group of radio button and which of the 4 radio buttons is selected.

Here's what I did

=====

button

=====             

instance name    rb1a       rb2b      rb3c     rb4d

group1                radio1    radio2   radio3   radio4

on(release){

     contents.grp1.rb1a.selection

}

Ned Murphy
Legend
November 19, 2009

You indicated you wanted to know which radio was clicked, so if you give them each an instance name that will be more determinable, but no, you do not need to assign instance names to each button to have the code work to detect which is selected and what the data of it is.

I am not sure what you are trying to do with the code:

on(release){

     contents.grp1.rb1a.selection

}

but whatever it is, you would be using: contents.grp1.selection instead of what you show. It is not a complete bit of coding, so I can't answer beyond that.  I assume you will be doing something similar as to what you did with the checkbox code.

Maybe the following will help you realize a thing or two.  Use this code for the button and see what you get...

on(release){

     trace(contents.grp1.selection);

     trace(contents.grp1.selection.data);

}

Then figure out how you need/want to manipulate that information.