13.15. Retrieving Values from Radio Button Groups

Problem

You want to retrieve a value from a group of radio buttons.

Solution

Use the radio button group’s selectedData property.

Discussion

As discussed in Recipe 13.5, radio buttons are typically used in groups. Therefore, you usually will want to retrieve the value from the selected radio button in the group. In order to do that, all you need to do is use the selectedData property of the radio button group.

Recall that when you create a radio button instance, you set the groupName parameter. The groupName parameter defines how the radio buttons are associated. Not only that, but it also creates a new ActionScript object with that same name. For example, if you create five radio buttons and assign each of them the group name of rbgQuizQuestion, Flash will automatically create an ActionScript object named rbgQuizQuestion. You can later use that ActionScript object to retrieve the value that has been selected for the entire group of five radio buttons. That object has a property named selectedData that will return the chosen value.

If you have defined a data parameter value for the radio buttons, the radio button group’s selectedData property will return the data value for the selected radio button. However, if you have not defined the data parameter value for the radio buttons, the selectedData property will simply return the chosen radio button’s label value.

In most scenarios, you will want to retrieve the selected radio button value only ...

Get Flash 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.