RadioButton.selection

Availability

Flash Player 6 (6.0.79.0).

Edition

Flash MX 2004.

Usage

radioButtonInstance.selection
radioButtonGroup.selection

Description

Property; behaves differently depending on whether you get or set the property. If you get the property, it returns the object reference of the currently selected radio button in a radio button group. If you set the property, it selects the specified radio button (passed as an object reference) in a radio button group and deselects the previously selected radio button.

Example

The following example creates three radio buttons in a radio group, positions the buttons, and creates a listener for a click event on the radio group. When the user clicks a radio button, the listener uses the selection property to display the instance name of the button that was clicked.

You first drag a RadioButton component from the Components panel to the current document's library, and then add the following code to Frame 1 of the main timeline.

/**
 Requires:
  - RadioButton component in library
*/

import mx.controls.RadioButton;

this.createClassObject(RadioButton, "first_rb", 10, {label:"first", groupName:"radioGroup"});
this.createClassObject(RadioButton, "second_rb", 20, {label:"second", groupName:"radioGroup"});
this.createClassObject(RadioButton, "third_rb", 30, {label:"third", groupName:"radioGroup"});

// Position radio buttons on Stage.
second_rb.move(0, first_rb.y + first_rb.height);
third_rb.move(0, second_rb.y + second_rb.height);

// Create listener object.
var rbListener:Object = new Object(); 
rbListener.click = function(evt_obj:Object){
 trace("The selected radio instance is " + radioGroup.selection);
} 
// Add listener.ll
radioGroup.addEventListener("click", rbListener);