Packagemx.controls
Classpublic class RadioButtonGroup
InheritanceRadioButtonGroup Inheritance EventDispatcher Inheritance Object
Implements IMXMLObject

The RadioButtonGroup control defines a group of RadioButton controls that act as a single mutually exclusive control; therefore, a user can select only one RadioButton control at a time. The id property is required when you use the <mx:RadioButtonGroup> tag to define the name of the group.

Notice that the RadioButtonGroup control is a subclass of EventDispatcher, not UIComponent, and implements the IMXMLObject interface. All other Flex visual components are subclasses of UIComponent, which implements the IUIComponent interface. The RadioButtonGroup control has support built into the Flex compiler that allows you to use the RadioButtonGroup control as a child of a Flex container, event though it does not implement IUIComponent. All other container children must implement the IUIComponent interface.

Therefore, if you try to define a visual component as a subclass of EventDispatcher that implements the IMXMLObject interface, you will not be able to use it as the child of a container.

MXML SyntaxexpandedHide MXML Syntax

The <mx:RadioButtonGroup> tag inherits all of the tag attributes of its superclass, and adds the following tag attributes:

  <mx:RadioButtonGroup
    Properties
    enabled="true|false"      
    id="No default"
    labelPlacement="right|left|top|bottom"
  
    Events
    change="No default"
    itemClick="No default"
  />
  

View the examples

See also

mx.controls.RadioButton
RadioButton control


Public Properties
 PropertyDefined By
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  enabled : Boolean
Determines whether selection is allowed.
RadioButtonGroup
  labelPlacement : String
Position of the RadioButton label relative to the RadioButton icon for each control in the group.
RadioButtonGroup
  numRadioButtons : int
[read-only] The number of RadioButtons that belong to this RadioButtonGroup.
RadioButtonGroup
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
  selectedValue : Object
The value of the value property of the selected RadioButton control in the group, if this has been set to be something other than null (the default value).
RadioButtonGroup
  selection : RadioButton
Contains a reference to the currently selected RadioButton control in the group.
RadioButtonGroup
Public Methods
 MethodDefined By
  
Constructor.
RadioButtonGroup
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event.
EventDispatcher
 Inherited
Dispatches an event into the event flow.
EventDispatcher
  
Returns the RadioButton control at the specified index.
RadioButtonGroup
 Inherited
Checks whether the EventDispatcher object has any listeners registered for a specific type of event.
EventDispatcher
 Inherited
Indicates whether an object has a specified property defined.
Object
  
Implementation of the IMXMLObject.initialized() method to support deferred instantiation.
RadioButtonGroup
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object.
EventDispatcher
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
 Inherited
Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type.
EventDispatcher
Events
 Event Summary Defined By
 Inherited[broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active.EventDispatcher
  Dispatched when the value of the selected RadioButton control in this group changes.RadioButtonGroup
 Inherited[broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive.EventDispatcher
  Dispatched when a user selects a RadioButton control in the group.RadioButtonGroup
Property Detail
enabledproperty
enabled:Boolean

Determines whether selection is allowed.

The default value is true.

This property can be used as the source for data binding. When this property is modified, it dispatches the enabledChanged event.



Implementation
    public function get enabled():Boolean
    public function set enabled(value:Boolean):void
labelPlacementproperty 
labelPlacement:String

Position of the RadioButton label relative to the RadioButton icon for each control in the group. You can override this setting for the individual controls.

Valid values in MXML are "right", "left", "bottom", and "top".

In ActionScript, you use the following constants to set this property: ButtonLabelPlacement.RIGHT, ButtonLabelPlacement.LEFT, ButtonLabelPlacement.BOTTOM, and ButtonLabelPlacement.TOP.

The default value is "right".

This property can be used as the source for data binding. When this property is modified, it dispatches the labelPlacementChanged event.



Implementation
    public function get labelPlacement():String
    public function set labelPlacement(value:String):void
numRadioButtonsproperty 
numRadioButtons:int  [read-only]

The number of RadioButtons that belong to this RadioButtonGroup.

The default value is "undefined".

This property can be used as the source for data binding. When this property is modified, it dispatches the numRadioButtonsChanged event.



Implementation
    public function get numRadioButtons():int
selectedValueproperty 
selectedValue:Object

The value of the value property of the selected RadioButton control in the group, if this has been set to be something other than null (the default value). Otherwise, selectedValue is the value of the label property of the selected RadioButton. If no RadioButton is selected, this property is null.

If you set selectedValue, Flex selects the RadioButton control whose value or label property matches this value.

The default value is null.

This property can be used as the source for data binding. When this property is modified, it dispatches the valueCommit event.



Implementation
    public function get selectedValue():Object
    public function set selectedValue(value:Object):void
selectionproperty 
selection:RadioButton

Contains a reference to the currently selected RadioButton control in the group. You can access the property in ActionScript only; it is not settable in MXML. Setting this property to null deselects the currently selected RadioButton control.

The default value is null.

This property can be used as the source for data binding. When this property is modified, it dispatches the valueCommit event.



Implementation
    public function get selection():RadioButton
    public function set selection(value:RadioButton):void
Constructor Detail
RadioButtonGroup()Constructor
public function RadioButtonGroup(document:IFlexDisplayObject = null)

Constructor.

Parameters
document:IFlexDisplayObject (default = null) — In simple cases where a class extends EventDispatcher, the document parameter should not be used.

See also

Method Detail
getRadioButtonAt()method
public function getRadioButtonAt(index:int):RadioButton

Returns the RadioButton control at the specified index.

Parameters

index:int — The index of the RadioButton control in the RadioButtonGroup control, where the index of the first control is 0.

Returns
RadioButton — The specified RadioButton control.
initialized()method 
public function initialized(document:Object, id:String):void

Implementation of the IMXMLObject.initialized() method to support deferred instantiation.

Parameters

document:Object — The MXML document that created this object.
 
id:String — The identifier used by document to refer to this object. If the object is a deep property on document, id is null.

See also

Event Detail
change Event
Event Object Type: flash.events.Event
property Event.type = flash.events.Event.CHANGE

Dispatched when the value of the selected RadioButton control in this group changes.

The Event.CHANGE constant defines the value of the type property of a change event object.

This event has the following properties:

PropertyValue
bubblestrue
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the Event object with an event listener.
targetThe object that has had its value modified. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
itemClick Event  
Event Object Type: mx.events.ItemClickEvent
property ItemClickEvent.type = mx.events.ItemClickEvent.ITEM_CLICK

Dispatched when a user selects a RadioButton control in the group. You can also set a handler for individual RadioButton controls.

The ItemClickEvent.ITEM_CLICK constant defines the value of the type property of the event object for an itemClick event.

The properties of the event object have the following values:

PropertyValue
bubblesfalse
cancelablefalse
currentTargetThe Object that defines the event listener that handles the event. For example, if you use myButton.addEventListener() to register an event listener, myButton is the value of the currentTarget.
indexThe index of the navigation item that was clicked.
itemThe item in the data provider of the navigation item that was clicked.
labelThe label of the navigation item that was clicked.
relatedObjectThe child object that generated the event.
targetThe Object that dispatched the event; it is not always the Object listening for the event. Use the currentTarget property to always access the Object listening for the event.
Examples How to use this example
RadioButtonGroupExample.mxml
<?xml version="1.0"?>
<!-- Simple example to demonstrate RadioButtonGroup control. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script>
        <![CDATA[
    
        import mx.controls.Alert;
        import  mx.events.ItemClickEvent;
    
        // Event handler function to display the selected button
        // in an Alert control.
        private function handleCard(event:ItemClickEvent):void {
            if (event.currentTarget.selectedValue == "AmEx") {
                    Alert.show("You selected American Express") 
            } 
            else {
                if (event.currentTarget.selectedValue == "MC") {
                    Alert.show("You selected MasterCard") 
                } 
                else {
                    Alert.show("You selected Visa") 
                }
            } 
        }
        ]]>
    </mx:Script>

    <mx:Panel title="RadioButtonGroup Control Example" height="75%" width="75%" 
        paddingTop="10" paddingLeft="10">
    
        <mx:Label width="100%" color="blue" 
            text="Select a type of credit card."/>

        <mx:RadioButtonGroup id="cardtype" itemClick="handleCard(event);"/>
        <mx:RadioButton groupName="cardtype" id="americanExpress" value="AmEx" 
            label="American Express" width="150" />
        <mx:RadioButton groupName="cardtype" id="masterCard" value="MC" 
            label="MasterCard" width="150" />
        <mx:RadioButton groupName="cardtype" id="visa" value="Visa" 
            label="Visa" width="150" />
        
    </mx:Panel>        
</mx:Application>