qnx.ui.buttons.RadioButton

RadioButton

Properties | Methods | Examples


Packageqnx.ui.buttons
Classpublic class RadioButton
InheritanceRadioButton Inheritance LabelButton Inheritance Button Inheritance SkinnableComponent Inheritance UIComponent Inheritance flash.display.MovieClip

The RadioButton component lets you force a user to make a single selection from a set of choices. This component must be used in a group of at least two RadioButton instances, and each RadioButton instance must be a member of a RadioButtonGroup. Each RadioButtonGroup must have a unique name. You can only select a single radio button at any given time. When you select a radio button, you deselect the currently selected radio button in the group.

By default, the RadioButton class uses the same skin as the LabelButton. You can set a label for each button by using the label property. The following image shows two radio button groups that use the default button style:

A radio button group.

You can use the setSkin() method to apply one of the included round radio button skins to a RadioButton instance. The RadioButtonSkinWhite and RadioButtonSkinBlack skins give each radio button the common, round appearance. The following image shows a set of RadioButton instances that use the RadioButtonSkinWhite skin:

A radio button group using the RadioButtonWhiteSkin.

The label property is not compatible with the RadioButtonSkinWhite and RadioButtonSkinBlack skins.



Class information:
PlayBook Tablet OS Version:   1.0.6

View the examples

See also

Button
RadioButtonGroup



Public Properties

 PropertyDefined By
 Inheritedcontainment : String
Gets or sets a property that determines how a component is contained within a parent container.
UIComponent
 InheritedembedFonts : Boolean
Gets or sets the embedFonts property of the internal TextField of the LabelButton.
LabelButton
  groupname : String
Determines the group for which the RadioButton belongs to.
RadioButton
 Inheritedlabel : String
Gets or sets the label for the button.
LabelButton
 Inheritedselected : Boolean
Gets or sets the selected property of the button.
Button
 Inheritedsize : Number
Gets or sets the size for this component (as a percentage of the container's size, or in pixels).
UIComponent
 InheritedsizeMode : String
Gets or sets the size mode for this component.
UIComponent
 InheritedsizeUnit : String
Gets or sets the unit of measure for the size property.
UIComponent
 Inheritedtoggle : Boolean
Gets or sets the toggle property of the button.
Button
 InheritedtruncationMode : String
Gets or sets the truncationMode of the button.
LabelButton

Public Methods

 MethodDefined By
  
Constructs a new RadioButton instance.
RadioButton
 Inherited
destroy():void
Call this method when you want to have your object collected by the garbage collector.
UIComponent
 Inherited
drawNow():void
Calls the draw() method.
UIComponent
 Inherited
getTextFormatForState(state:String):TextFormat
Returns the TextFormat object for a specified state.
LabelButton
 Inherited
invalidate(property:String = all, invalidateNow:Boolean = false):void
Marks the property as invalid and the draw() method is called on the next frame or the next render, whichever comes first.
UIComponent
 Inherited
setPosition(x:Number, y:Number):void
Sets the x and y position of the component.
UIComponent
 Inherited
setSize(w:Number, h:Number):void
Sets the width and height of the component.
UIComponent
 Inherited
setSkin(cellSkin:Object):void
Set the skin object on the component for it to render.
SkinnableComponent
 Inherited
setTextFormatForState(format:TextFormat, state:String):void
Sets the TextFormat object for the label for a given state.
LabelButton

Protected Methods

 MethodDefined By
 Inherited
callLater(method:Function):void
Calls the specified method on the next frame or the next render, which ever happens first.
UIComponent
 Inherited
createInstance(linkage:Object):DisplayObject
Calling this method will attempt to create a DisplayObject instance based on the value of the linkage parameter.
UIComponent
 Inherited
draw():void
Called every time you set the width and height of the component.
UIComponent
 Inherited
isInvalid(property:String, ... properties):Boolean
Checks to see if the property is invalid and returns true if it is.
UIComponent
 Inherited
onAdded():void
Called when the instance is added to the stage.
UIComponent
 Inherited
onRemoved():void
Called when the instance is removed from the stage.
UIComponent
 Inherited
setEnabled(val:Boolean):void
Called when the enabled property changes.
UIComponent
 Inherited
validate(property:String = all):void
Lets the component know that the specified property has been validated.
UIComponent

Property Detail

groupname


groupname:String

Determines the group for which the RadioButton belongs to. You must specify the name of a valid RadioButtonGroup in order to distinguish a related set of RadioButton instances. If no group with the specified unique name exists, a new RadioButtonGroup instance will be created and the button will be added to the new group.

A RadioButton can only belong to a single group at any given time.

The default value is QNXRadioButtonGroup.


Implementation

public function get groupname():String
public function set groupname(value:String):void

Constructor Detail

RadioButton()


public function RadioButton()

Constructs a new RadioButton instance.

Examples

In the following example, six RadioButton instances and two RadioButtonGroup instances are created. The RadioButtonGroup instances are given unique names by passing in unique group names to the getGroup() method.

package
{
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    
    import qnx.ui.buttons.RadioButton;
    import qnx.ui.buttons.RadioButtonGroup;
    
    [SWF(height="600", width="1024", frameRate="30",
    backgroundColor="#FFFFFF")]
    public class RadioButtonSample extends Sprite
    {
        
        public function RadioButtonSample()
        {
            initializeUI();
            
        }
    
        private function initializeUI():void
        {
            var rb1:RadioButton = new RadioButton();
            rb1.setPosition(100, 100)
            rb1.label = "Meal option 1";
            rb1.groupname = "rbg1_meals13";
            addChild( rb1 );
            
            var rb2:RadioButton = new RadioButton();
            rb2.setPosition( rb1.x, rb1.y + 40 );
            rb2.label = "Meal option 2";
            rb2.groupname = "rbg1_meals13";
            addChild( rb2 );
            
            
            var rb3:RadioButton = new RadioButton();
            rb3.setPosition( rb1.x, rb2.y + 40 );
            rb3.label = "Meal option 3";
            rb3.groupname = "rbg1_meals13";
            addChild( rb3 );
            
            
            var rb4:RadioButton = new RadioButton();
            rb4.setPosition( 300, 100 )
            rb4.label = "Meal option 4";
            rb4.groupname = "rbg1_meals46";
            addChild( rb4 );
            
            var rb5:RadioButton = new RadioButton();
            rb5.setPosition( rb4.x, rb4.y + 40 );
            rb5.label = "Meal option 5";
            rb5.groupname = "rbg1_meals46";
            addChild( rb5 );
            
            
            var rb6:RadioButton = new RadioButton();
            rb6.setPosition( rb4.x, rb5.y + 40 );
            rb6.label = "Meal option 6";
            rb6.groupname = "rbg1_meals46";
            addChild( rb6 );
            
            var rbg1:RadioButtonGroup = RadioButtonGroup.getGroup( "rbg1_meals13" );
            rbg1.addEventListener( MouseEvent.CLICK, rbg1Change );
            rbg1.setSelectedRadioButton( rb2 );
            
            var rbg2:RadioButtonGroup = RadioButtonGroup.getGroup( "rbg1_meals46" );
            rbg2.addEventListener( MouseEvent.CLICK, rbg2Change );
            rbg2.setSelectedRadioButton( rb5 );
        }
        
        
        private function rbg1Change( event:MouseEvent ):void{
            trace("rbg1 change event");    
            
        }
        
        private function rbg2Change( event:MouseEvent) :void{
            trace("rbg2 change event");    
            
        }
        
    }
}
     
     
     

In the following listing, a set of RadioButton instances are created that use the RadioButtonSkinWhite class. The RadioButton instances in this example appear round. When the user clicks a radio button, the button is selected and becomes highlighted with a black dot.

package
{
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    
    import qnx.ui.buttons.RadioButton;
    import qnx.ui.buttons.RadioButtonGroup;
    import qnx.ui.skins.buttons.RadioButtonSkinWhite;
    import qnx.ui.skins.buttons.RadioButtonSkinBlack;
    
    [SWF(height="600", width="1024", frameRate="30",
    backgroundColor="#FFFFFF")]
    public class RadioButtonRoundSample extends Sprite
    {
        public function RadioButtonRoundSample()
        {
            initializeUI();
        }
    
        private function initializeUI():void
        {
            var rb1:RadioButton = new RadioButton();
            rb1.setPosition(100, 100)            
            rb1.setSkin(RadioButtonSkinWhite);
            rb1.groupname = "rbg1_gp";
            addChild( rb1 );
            
            var rb2:RadioButton = new RadioButton();
            rb2.setPosition( rb1.x, rb1.y + 40 );
            rb2.setSkin(RadioButtonSkinWhite);            
            rb2.groupname = "rbg1_gp";
            addChild( rb2 );
            
            var rb3:RadioButton = new RadioButton();
            rb3.setPosition( rb1.x, rb2.y + 40 );
            rb3.setSkin(RadioButtonSkinWhite);            
            rb3.groupname = "rbg1_gp";
            addChild( rb3 );
                    
            var rbg1:RadioButtonGroup;
            rbg1 = RadioButtonGroup.getGroup( "rbg1_gp" );
            rbg1.addButton( rb1 );
            rbg1.addButton( rb2 );
            rbg1.addButton( rb3 );
            rbg1.addEventListener( MouseEvent.CLICK, rbgChange );
            rbg1.setSelectedRadioButton( rb2 );
        }
        
        private function rbgChange( event:MouseEvent ):void
        {
            trace("rbg1 change event");
        }
    }
}