ToggleButton |
A switch button with an on and off state. The button can toggle independently or be part of a group of ToggleButtons where only one can be on at a time.
BubbleButton, LabelButton, ShapeButton.
ToggleButton | A switch button with an on and off state. |
Public constants | |
DEFAULT_SIZE | Default button diameter in pixels |
defaultColor | Default button base color |
Private toggle groups | |
groups | Static class level array of toggle groups. |
groupId | Group reference for this button instance, null if independent. |
Private state shapes | |
downOnState | Button shape shown when the button is pressed down and its state is on |
upOnState | Button shape shown when the button is not pressed down and its state is on |
downOffState | Button shape shown when the button is pressed down and its state is off |
upOffState | Button shape shown when the button is not pressed down and its state is off |
Private data members | |
lastState | Reference to the last state shape the button has been shown with |
callback | Function called when the button changes state |
toggleState | Current boolean state of this button |
toggleLabel | Text label shown to convey the function of the button |
Constructor | |
ToggleButton | Creates a switch button that a user can toggle on or off. |
Public properties | |
text | Change the text of the button label |
state | Get the current state of the toggle button |
state | Set the state of the toggle button programmatically. |
Internal Group methods | |
addToGroup | Adds a button instance to a group |
removeFromGroup | Removes a button instance from a group |
propagateToGroup | Propagates a state change for a button instance throughout a group |
findGroup | Finds the internal group instance with the id of the given <groupObj>. |
Event handlers | |
mouseDownHandler | Change state when the button is pressed |
mouseUpHandler | Change state when the button is released |
mouseClickHandler | Button click handler calls back to user supplied handler if present |
WidgetInterface | |
active | Sets the state of the widget to active or inactive. |
activate | Activates the widget, adds its event listeners |
disactivate | Disactivates the widget, removes its event listeners |
dispose | Dispose of all resources used or referenced in the instance. |
destructor | Removes used resources, references and graphics |
private static var groups: Array
Static class level array of toggle groups. Each element is a dynamic object with an id property holding the group object reference and an array of button instance references belonging to the group.
Since there is only one array in an application globally reachable objects such as the stage such not be used to indicate a group. It is better to use a reference to for example a Label describing the group or if there is only one group in a class then the this reference.
public function ToggleButton( owner: String, labelText: String, color: uint = Color.Grey, labelColor: uint = defaultColor, groupObject: Object = null, clickHandler: Function = null, initialState: Boolean = false, size: uint = DEFAULT_SIZE, customOnShapeFunction: Function = null, customOffShapeFunction: Function = null )
Creates a switch button that a user can toggle on or off. The default visual representation is as a small bubble button with a dot in it when it is selected. Groups of toggles can be created that switches off other buttons in the group when a new is selcted.
owner | name of registered owner; see WidgetSprite.register |
labelText | Text indicating the function of the button, null for no label (default) |
color | base theme color for the button |
labelColor | color for the label text |
groupObject | reference to an object (such as this or a label) if belonging to a group (default null) |
clickHandler | a callback function that is called when the button changes state |
initialState | true if the button is on initially, false otherwise (default false) |
size | width the button, determines default size and label placement (default 15) |
customOnShapeFunction | function returning a graphics shape for the button on state (default null) |
customOffShapeFunction | function returning a graphics shape for the button off state (default null) |
clickHandler | function onToggleButtonClick(state:Boolean):void |
private function findGroup( groupObj: Object ):Object
Finds the internal group instance with the id of the given <groupObj>.
It is currently a linear search based on the assumption that there are relatively few groups in an application.
groupObj | reference to a group object |
a reference to the internal dynamic group if found, null otherwise
Default button diameter in pixels
public static const DEFAULT_SIZE: uint
Default button base color
public static const defaultColor: int
Static class level array of toggle groups.
private static var groups: Array
Group reference for this button instance, null if independent.
private var groupId: Object
Button shape shown when the button is pressed down and its state is on
private var downOnState: Shape
Button shape shown when the button is not pressed down and its state is on
private var upOnState: Shape
Button shape shown when the button is pressed down and its state is off
private var downOffState: Shape
Button shape shown when the button is not pressed down and its state is off
private var upOffState: Shape
Reference to the last state shape the button has been shown with
private var lastState: DisplayObject
Function called when the button changes state
private var callback: Function
Current boolean state of this button
private var toggleState: Boolean
Text label shown to convey the function of the button
private var toggleLabel: Label
Creates a switch button that a user can toggle on or off.
public function ToggleButton( owner: String, labelText: String, color: uint = Color.Grey, labelColor: uint = defaultColor, groupObject: Object = null, clickHandler: Function = null, initialState: Boolean = false, size: uint = DEFAULT_SIZE, customOnShapeFunction: Function = null, customOffShapeFunction: Function = null )
Change the text of the button label
public function set text( labelText: String ):void
Get the current state of the toggle button
public function get state():Boolean
Adds a button instance to a group
private function addToGroup( groupObj: Object, thisInstance: ToggleButton ):void
Removes a button instance from a group
private function removeFromGroup( groupObj: Object, thisInstance: ToggleButton ):void
Propagates a state change for a button instance throughout a group
private function propagateToGroup( groupObj: Object, thisInstance: ToggleButton ):void
Finds the internal group instance with the id of the given groupObj.
private function findGroup( groupObj: Object ):Object
Change state when the button is pressed
private function mouseDownHandler( event: MouseEvent ):void
Change state when the button is released
private function mouseUpHandler( event: MouseEvent ):void
Button click handler calls back to user supplied handler if present
private function mouseClickHandler( event: MouseEvent ):void
Sets the state of the widget to active or inactive.
public function set active( state: Boolean ):void
Activates the widget, adds its event listeners
private function activate():void
Disactivates the widget, removes its event listeners
private function disactivate():void
Dispose of all resources used or referenced in the instance.
public function dispose():void
Removes used resources, references and graphics
private function destructor():void
Register the owner of a widget.
public function register( owner: String ):void