| Package | qnx.ui.buttons |
| Class | public class RadioButton |
| Inheritance | RadioButton LabelButton Button SkinnableComponent UIComponent flash.display.MovieClip |
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:
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:
The label property is not compatible with the RadioButtonSkinWhite and RadioButtonSkinBlack skins.
See also
| Property | Defined By | ||
|---|---|---|---|
![]() | containment : String
Gets or sets a property that determines how a component is contained within a parent container. | UIComponent | |
![]() | embedFonts : 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 | ||
![]() | label : String
Gets or sets the label for the button. | LabelButton | |
![]() | selected : Boolean
Gets or sets the selected property of the button. | Button | |
![]() | size : Number
Gets or sets the size for this component (as a percentage of the
container's size, or in pixels). | UIComponent | |
![]() | sizeMode : String
Gets or sets the size mode for this component. | UIComponent | |
![]() | sizeUnit : String
Gets or sets the unit of measure for the size property. | UIComponent | |
![]() | toggle : Boolean
Gets or sets the toggle property of the button. | Button | |
| Method | Defined By | ||
|---|---|---|---|
Constructs a new RadioButton instance. | RadioButton | ||
![]() | destroy():void
Call this method when you want to have your object collected by the garbage collector. | UIComponent | |
![]() | drawNow():void
Calls the draw() method. | UIComponent | |
![]() | getTextFormatForState(state:String):TextFormat
Returns the TextFormat object for a specified state. | LabelButton | |
![]() | invalidate(property:String, 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 | |
![]() | setPosition(x:Number, y:Number):void
Sets the x and y position of the component. | UIComponent | |
![]() | setSize(w:Number, h:Number):void
Sets the width and height of the component. | UIComponent | |
![]() | setSkin(cellSkin:Object):void
Set the skin object on the component for it to render. | SkinnableComponent | |
![]() | setTextFormatForState(format:TextFormat, state:String):void
Sets the TextFormat object for the label for a given state. | LabelButton | |
| groupname | property |
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.
public function get groupname():String public function set groupname(value:String):void| RadioButton | () | Constructor |
public function RadioButton()
Constructs a new RadioButton instance.
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;
rbg1 = RadioButtonGroup.getGroup( "rbg1_meals13" );
rbg1.addButton( rb1 );
rbg1.addButton( rb2 );
rbg1.addButton( rb3 );
rbg1.addEventListener( MouseEvent.CLICK, rbg1Change );
rbg1.setSelectedRadioButton( rb2 );
var rbg2:RadioButtonGroup;
rbg2 = RadioButtonGroup.getGroup( "rbg1_meals46" );
rbg2.addButton( rb4 );
rbg2.addButton( rb5 );
rbg2.addButton( rb6 );
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");
}
}
}