|
Flash CS4 Resources |
Use the RadioButton componentThe RadioButton component lets you force a user to make a single choice within a set of choices. This component must be used in a group of at least two RadioButton instances. Only one member of the group can be selected at any given time. Selecting one radio button in a group deselects the currently selected radio button in the group. You set the groupName parameter to indicate which group a radio button belongs to. A radio button is a fundamental part of many form applications on the web. You can use radio buttons wherever you want a user to make one choice from a group of options. For example, you would use radio buttons in a form to ask which credit card a customer wants to use. User interaction with the RadioButton componentA radio button can be enabled or disabled. A disabled radio button doesn’t receive mouse or keyboard input. When the user clicks or tabs into a RadioButton component group, only the selected radio button receives focus. The user can then use the following keys to control it:
For more information about controlling focus, see the IFocusManager interface and the FocusManager class in the ActionScript 3.0 Language and Components Reference and Work with FocusManager. A live preview of each RadioButton instance on the Stage reflects changes made to parameters in the Property inspector or Component inspector during authoring. However, the mutual exclusion of selection does not display in the live preview. If you set the selected parameter to true for two radio buttons in the same group, they both appear selected even though only the last instance created appears selected at run time. For more information, see RadioButton component parameters. When you add the RadioButton component to an application, you can make it accessible to a screen reader by adding the following lines of code: import fl.accessibility.RadioButtonAccImpl; RadioButtonAccImpl.enableAccessibility(); You enable accessibility for a component only once, regardless of how many instances you have of the component. For more information, see Chapter 18, “Creating Accessible Content,” in Using Flash . RadioButton component parametersYou can set the following authoring parameters in the Property inspector or in the Component inspector for each RadioButton component instance: groupName, label, LabelPlacement, selected , and value . Each of these parameters has a corresponding ActionScript property of the same name. For information on the possible values for these parameters, see the RadioButton class in the ActionScript 3.0 Language and Components Reference . You can write ActionScript to set additional options for RadioButton instances using the methods, properties, and events of the RadioButton class. Create an application with the RadioButton componentThe following procedure explains how to add RadioButton components to an application while authoring. In this example, the RadioButtons are used to present a yes-or-no question. The data from the RadioButton is displayed in a TextArea.
Create a RadioButton using ActionScriptThis example uses ActionScript to create three RadioButtons for the colors red, blue, and green and draws a gray box. The value property for each RadioButton specifies the hexadecimal value for the color associated with the button. When a user clicks one of the RadioButtons, the clickHandler() function calls drawBox() , passing the color from the RadioButton’s value property to color the box.
|