13.5. Adding a Radio Button Form Control

Problem

You want to add a radio button to your Flash application.

Solution

Add an instance of the RadioButton component and set the parameters.

Discussion

Radio buttons are typically used in groups, and they allow the user to select one option from the group. When the user clicks on one radio button, it gets selected and the others in the group get deselected. Adding radio buttons is almost as simple as adding checkboxes. The only additional thing you need to make sure of with radio buttons is that you specify a value for the groupName parameter.

To add a radio button to your application, drag an instance from the Component Inspector onto the stage. As with any component, give it an instance name in the Property inspector. You can then set the parameters for the instance using the Property inspector or the Component Inspector panel. You’ll likely notice that radio buttons have the same three parameters as checkboxes. You can set those values appropriately.

In addition to the three parameters that they share with checkboxes, radio boxes also have a groupName parameter. The group name is important for several reasons. It is what tells Flash which radio buttons are grouped together so that it knows how to select and deselect radio buttons based on user interaction. All radio buttons with the same group name will automatically interact with one another in the way described earlier in this recipe. Another reason that the group name is important is that ...

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.