| Package | km.components |
| Class | public class ButtonGroup |
| Inheritance | ButtonGroup flash.events.EventDispatcher |
import km.components.*;
import km.skins.*;
var tf:TextField;
var b1:LabelButton, b2:LabelButton, b3:LabelButton;
// Add a dynamic textfield.
tf = new TextField();
addChild(tf);
// Add a label button component.
b1 = new LabelButton();
ScriptedSkin.applyTo(b1);
b1.setSize(90,24);
b1.move(20,30);
addChild(b1);
// Clone the first button and add the clone.
// This way we don't have to skin all buttons separately.
b2 = b1.clone();
b2.y = 60;
addChild(b2);
// Do the same for button three.
b3 = b1.clone();
b3.y = 90;
addChild(b3);
// Set the labels for the buttons
b1.label.text = 'Button 1';
b2.label.text = 'Button 2';
b3.label.text = 'Button 3';
// Create a button group and add the buttons
var bg:ButtonGroup = new ButtonGroup();
bg.addButton(b1, 1);
bg.addButton(b2, 2);
bg.addButton(b3, 3);
// Set the on change handler
bg.onChange = function(){
tf.text = bg.data;
}
| Property | Defined by | ||
|---|---|---|---|
| data : * [read-only] Gets the data associated with the selected button.
| ButtonGroup | ||
| onChange : Function onChange handler.
| ButtonGroup | ||
| selected : * Gets or sets the selected button.
| ButtonGroup | ||
| Method | Defined by | ||
|---|---|---|---|
|
ButtonGroup(operationMode:int = 1)
| ButtonGroup | ||
|
addButton(button:*, data:* = null):void
Adds a button to the group.
| ButtonGroup | ||
|
removeButton(button:*):void
Removes a button from the group.
| ButtonGroup | ||
| Event | Summary | Defined by | ||
|---|---|---|---|---|
| The change event is broadcasted when another button is selected. | ButtonGroup | |||
| data | property |
data:* [read-only]Gets the data associated with the selected button.
Implementation public function get data():*
| onChange | property |
public var onChange:FunctiononChange handler.
| selected | property |
selected:* [read-write]Gets or sets the selected button.
Implementation public function get selected():*
public function set selected(value:*):void
| ButtonGroup | () | constructor |
public function ButtonGroup(operationMode:int = 1)Parameters
operationMode:int (default = 1) — 1 = hold, 2 = switch.
|
| addButton | () | method |
public function addButton(button:*, data:* = null):voidAdds a button to the group.
Parametersbutton:* — The button to add to the group.
|
|
data:* (default = null) — The data associated with the button.
|
| removeButton | () | method |
public function removeButton(button:*):voidRemoves a button from the group.
Parametersbutton:* — The button to remove from the group.
|
| change | event |
flash.events.Event
The change event is broadcasted when another button is selected. It's also possible to use the onChange handler.