Packagefeathers.controls
Classpublic class ToggleSwitch
InheritanceToggleSwitch Inheritance FeathersControl Inheritance starling.display.Sprite
Implements IToggle, IFocusDisplayObject, ITextBaselineControl, IStateContext

Product Version : Feathers 1.0.0

Similar to a light switch with on and off states. Generally considered an alternative to a check box.

The following example programmatically selects a toggle switch and listens for when the selection changes:

var toggle:ToggleSwitch = new ToggleSwitch();
toggle.isSelected = true;
toggle.addEventListener( Event.CHANGE, toggle_changeHandler );
this.addChild( toggle );

See also

How to use the Feathers ToggleSwitch component
feathers.controls.Check


Public Properties
 PropertyDefined By
 InheritedaddedEffect : Function
An optional effect that is activated when the component is added to the stage.
FeathersControl
  baseline : Number
[read-only] Returns the text baseline measurement, in pixels.
ToggleSwitch
  currentState : String
[read-only] The current state of the toggle switch.
ToggleSwitch
  defaultLabelProperties : Object
An object that stores properties for the toggle switch's label text renderers when the toggle switch is enabled, and the properties will be passed down to the text renderers when the toggle switch validates.
ToggleSwitch
 InheriteddefaultTextEditorFactory : Function
[static] A function used by all UI controls that support text editor to create an ITextEditor instance.
FeathersControl
 InheriteddefaultTextRendererFactory : Function
[static] A function used by all UI controls that support text renderers to create an ITextRenderer instance.
FeathersControl
 Inheriteddepth : int
[read-only] The component's depth in the display list, relative to the stage.
FeathersControl
  disabledLabelProperties : Object
An object that stores properties for the toggle switch's label text renderers when the toggle switch is disabled, and the properties will be passed down to the text renderers when the toggle switch validates.
ToggleSwitch
 InheritedeffectsSuspended : Boolean
[read-only] Indicates if effects have been suspended.
FeathersControl
 InheritedexplicitHeight : Number
[read-only] The height value explicitly set by passing a value to the height setter or by calling the setSize() function.
FeathersControl
 InheritedexplicitMaxHeight : Number
[read-only] The maximum height value explicitly set by passing a value to the maxHeight setter.
FeathersControl
 InheritedexplicitMaxWidth : Number
[read-only] The maximum width value explicitly set by passing a value to the maxWidth setter.
FeathersControl
 InheritedexplicitMinHeight : Number
[read-only] The minimum height value explicitly set by passing a value to the minHeight setter.
FeathersControl
 InheritedexplicitMinWidth : Number
[read-only] The minimum width value explicitly set by passing a value to the minWidth setter.
FeathersControl
 InheritedexplicitWidth : Number
[read-only] The width value explicitly set by passing a value to the width setter or to the setSize() method.
FeathersControl
 InheritedfocusInEffect : Function
An optional effect that is activated when the component receives focus.
FeathersControl
 InheritedfocusManager : IFocusManager
The implementation of this property is provided for convenience, but it cannot be used unless a subclass implements the IFocusDisplayObject interface. The current focus manager for this component.
FeathersControl
 InheritedfocusOutEffect : Function
An optional effect that is activated when the component loses focus.
FeathersControl
 InheritedfocusOwner : IFocusDisplayObject
The implementation of this property is provided for convenience, but it cannot be used unless a subclass implements the IFocusDisplayObject interface. Used for associating focusable display objects that are not direct children with an "owner" focusable display object, such as pop-ups.
FeathersControl
  globalStyleProvider : IStyleProvider
[static] The default IStyleProvider for all ToggleSwitch components.
ToggleSwitch
 Inheritedheight : Number
[override] The height of the component, in pixels.
FeathersControl
 InheritedhideEffect : Function
An optional effect that is activated when the component is hidden.
FeathersControl
 InheritedincludeInLayout : Boolean
Determines if the ILayout should use this object or ignore it.
FeathersControl
 InheritedisCreated : Boolean
[read-only] Determines if the component has been initialized and validated for the first time.
FeathersControl
 InheritedisEnabled : Boolean
Indicates whether the control is interactive or not.
FeathersControl
 InheritedisFocusEnabled : Boolean
The implementation of this property is provided for convenience, but it cannot be used unless a subclass implements the IFocusDisplayObject interface. Determines if this component can receive focus.
FeathersControl
 InheritedisInitialized : Boolean
[read-only] Determines if the component has been initialized yet.
FeathersControl
 InheritedisQuickHitAreaEnabled : Boolean
Similar to mouseChildren on the classic display list.
FeathersControl
  isSelected : Boolean
Indicates if the toggle switch is selected (ON) or not (OFF).
ToggleSwitch
 InheritedisShowingFocus : Boolean
[read-only] The implementation of this method is provided for convenience, but it cannot be used unless a subclass implements the IFocusDisplayObject interface. Indicates if the showFocus() method has been called on the object when it has focus.
FeathersControl
  labelFactory : Function
A function used to instantiate the toggle switch's label text renderer sub-components, if specific factories for those label text renderers are not provided.
ToggleSwitch
 InheritedlayoutData : ILayoutData
Extra parameters associated with this display object that will be used by the layout algorithm.
FeathersControl
 InheritedmaintainTouchFocus : Boolean
[read-only] The implementation of this method is provided for convenience, but it cannot be used unless a subclass implements the IFocusDisplayObject interface. If true, the display object should remain in focus, even if something else is touched.
FeathersControl
 InheritedmaxHeight : Number
The maximum recommended height to be used for self-measurement and, optionally, by any code that is resizing this component.
FeathersControl
 InheritedmaxWidth : Number
The maximum recommended width to be used for self-measurement and, optionally, by any code that is resizing this component.
FeathersControl
 InheritedminHeight : Number
The minimum recommended height to be used for self-measurement and, optionally, by any code that is resizing this component.
FeathersControl
 InheritedminTouchHeight : Number
If using isQuickHitAreaEnabled, and the hit area's height is smaller than this value, it will be expanded.
FeathersControl
 InheritedminTouchWidth : Number
If using isQuickHitAreaEnabled, and the hit area's width is smaller than this value, it will be expanded.
FeathersControl
 InheritedminWidth : Number
The minimum recommended width to be used for self-measurement and, optionally, by any code that is resizing this component.
FeathersControl
 InheritedmoveEffect : Function
An optional effect that is activated when the component is moved to a new position.
FeathersControl
 InheritednextDownFocus : IFocusDisplayObject
The implementation of this property is provided for convenience, but it cannot be used unless a subclass implements the IFocusDisplayObject interface. The next object that will receive focus when Keyboard.DOWN is pressed at KeyLocation.D_PAD and a focus manager is enabled.
FeathersControl
 InheritednextLeftFocus : IFocusDisplayObject
The implementation of this property is provided for convenience, but it cannot be used unless a subclass implements the IFocusDisplayObject interface. The next object that will receive focus when Keyboard.LEFT is pressed at KeyLocation.D_PAD and a focus manager is enabled.
FeathersControl
 InheritednextRightFocus : IFocusDisplayObject
The implementation of this property is provided for convenience, but it cannot be used unless a subclass implements the IFocusDisplayObject interface. The next object that will receive focus when Keyboard.RIGHT is pressed at KeyLocation.D_PAD and a focus manager is enabled.
FeathersControl
 InheritednextTabFocus : IFocusDisplayObject
The implementation of this property is provided for convenience, but it cannot be used unless a subclass implements the IFocusDisplayObject interface. The next object that will receive focus when the tab key is pressed when a focus manager is enabled.
FeathersControl
 InheritednextUpFocus : IFocusDisplayObject
The implementation of this property is provided for convenience, but it cannot be used unless a subclass implements the IFocusDisplayObject interface. The next object that will receive focus when Keyboard.UP is pressed at KeyLocation.D_PAD and a focus manager is enabled.
FeathersControl
  offLabelFactory : Function
A function used to instantiate the toggle switch's off label text renderer sub-component.
ToggleSwitch
  offLabelProperties : Object
An object that stores properties for the toggle switch's "off" label text renderer, and the properties will be passed down to the text renderer when the toggle switch validates.
ToggleSwitch
  offTrackFactory : Function
A function used to generate the toggle switch's "off" track sub-component.
ToggleSwitch
  offTrackProperties : Object
An object that stores properties for the toggle switch's "off" track, and the properties will be passed down to the "off" track when the toggle switch validates.
ToggleSwitch
  onLabelFactory : Function
A function used to instantiate the toggle switch's on label text renderer sub-component.
ToggleSwitch
  onLabelProperties : Object
An object that stores properties for the toggle switch's "on" label text renderer, and the properties will be passed down to the text renderer when the toggle switch validates.
ToggleSwitch
  onTrackFactory : Function
A function used to generate the toggle switch's "on" track sub-component.
ToggleSwitch
  onTrackProperties : Object
An object that stores properties for the toggle switch's "on" track, and the properties will be passed down to the "on" track when the toggle switch validates.
ToggleSwitch
 InheritedpreviousTabFocus : IFocusDisplayObject
The implementation of this property is provided for convenience, but it cannot be used unless a subclass implements the IFocusDisplayObject interface. The previous object that will receive focus when the tab key is pressed while holding shift when a focus manager is enabled.
FeathersControl
 InheritedresizeEffect : Function
An optional effect that is activated when the component is resized with new dimensions.
FeathersControl
 InheritedshowEffect : Function
An optional effect that is activated when the component is shown.
FeathersControl
 InheritedstyleName : String
The concatenated styleNameList, with values separated by spaces.
FeathersControl
 InheritedstyleNameList : TokenList
[read-only] Contains a list of all "styles" assigned to this control.
FeathersControl
 InheritedstyleProvider : IStyleProvider
When a component initializes, a style provider may be used to set properties that affect the component's visual appearance.
FeathersControl
  thumbFactory : Function
A function used to generate the toggle switch's thumb sub-component.
ToggleSwitch
  thumbProperties : Object
An object that stores properties for the toggle switch's thumb sub-component, and the properties will be passed down to the thumb when the toggle switch validates.
ToggleSwitch
 InheritedtoolTip : String
Text to display in a tool tip to when hovering over this component, if the ToolTipManager is enabled.
FeathersControl
 Inheritedwidth : Number
[override] The width of the component, in pixels.
FeathersControl
Protected Properties
 PropertyDefined By
 InheritedactualHeight : Number = 0
The final height value that should be used for layout.
FeathersControl
 InheritedactualMinHeight : Number = 0
The final minimum height value that should be used for layout.
FeathersControl
 InheritedactualMinWidth : Number = 0
The final minimum width value that should be used for layout.
FeathersControl
 InheritedactualWidth : Number = 0
The final width value that should be used for layout.
FeathersControl
 InheriteddefaultStyleProvider : IStyleProvider
[read-only] When the FeathersControl constructor is called, the styleProvider property is set to this value.
FeathersControl
  offLabelStyleName : String = "feathers-toggle-switch-off-label"
The value added to the styleNameList of the off label text renderer.
ToggleSwitch
  offTextRenderer : ITextRenderer
The "off" text renderer sub-component.
ToggleSwitch
  offTrack : DisplayObject
The "off" track sub-component.
ToggleSwitch
  offTrackStyleName : String = "feathers-toggle-switch-off-track"
The value added to the styleNameList of the off track.
ToggleSwitch
  onLabelStyleName : String = "feathers-toggle-switch-on-label"
The value added to the styleNameList of the off label text renderer.
ToggleSwitch
  onTextRenderer : ITextRenderer
The "on" text renderer sub-component.
ToggleSwitch
  onTrack : DisplayObject
The "on" track sub-component.
ToggleSwitch
  onTrackStyleName : String = "feathers-toggle-switch-on-track"
The value added to the styleNameList of the on track.
ToggleSwitch
  thumb : DisplayObject
The thumb sub-component.
ToggleSwitch
  thumbStyleName : String = "feathers-toggle-switch-thumb"
The value added to the styleNameList of the thumb.
ToggleSwitch
Public Methods
 MethodDefined By
  
Constructor.
ToggleSwitch
 Inherited
getBounds(targetSpace:DisplayObject, resultRect:Rectangle = null):Rectangle
[override] Feathers components use an optimized getBounds() implementation that may sometimes behave differently than regular Starling display objects.
FeathersControl
  
getOffLabelFontStylesForState(state:String):TextFormat
Gets the font styles to be used to display the toggle switch's off label text when the toggle switch's currentState property matches the specified state value.
ToggleSwitch
  
getOnLabelFontStylesForState(state:String):TextFormat
Gets the font styles to be used to display the toggle switch's on label text when the toggle switch's currentState property matches the specified state value.
ToggleSwitch
 Inherited
hideFocus():void
The implementation of this method is provided for convenience, but it cannot be used unless a subclass implements the IFocusDisplayObject interface.
FeathersControl
 Inherited
If the component has not yet initialized, initializes immediately.
FeathersControl
 Inherited
invalidate(flag:String):void
Call this function to tell the UI control that a redraw is pending.
FeathersControl
 Inherited
isInvalid(flag:String = null):Boolean
Indicates whether the control is pending validation or not.
FeathersControl
 Inherited
move(x:Number, y:Number):void
Sets both the x and the y positions of the control in a single function call.
FeathersControl
 Inherited
removeFromParentWithEffect(effect:Function, dispose:Boolean = false):void
Plays an effect before removing the component from its parent.
FeathersControl
 Inherited
Resets the styleProvider property to its default value, which is usually the global style provider for the component.
FeathersControl
 Inherited
Indicates that effects should be re-activated after being suspended.
FeathersControl
  
setOffLabelFontStylesForState(state:String, format:TextFormat):void
Sets the font styles to be used to display the toggle switch's off label text when the toggle switch's currentState property matches the specified state value.
ToggleSwitch
  
setOnLabelFontStylesForState(state:String, format:TextFormat):void
Sets the font styles to be used to display the toggle switch's on label text when the toggle switch's currentState property matches the specified state value.
ToggleSwitch
  
setSelectionWithAnimation(isSelected:Boolean):void
Changes the isSelected property, but animates the thumb to the new position, as if the user tapped the toggle switch.
ToggleSwitch
 Inherited
setSize(width:Number, height:Number):void
Sets both the width and the height of the control in a single function call.
FeathersControl
 Inherited
showFocus():void
The implementation of this method is provided for convenience, but it cannot be used unless a subclass implements the IFocusDisplayObject interface.
FeathersControl
 Inherited
Indicates that effects should not be activated temporarily.
FeathersControl
 Inherited
validate():void
Immediately validates the display object, if it is invalid.
FeathersControl
Protected Methods
 MethodDefined By
  
If the component's dimensions have not been set explicitly, it will measure its content and determine an ideal size for itself.
ToggleSwitch
 Inherited
clearInvalidationFlag(flag:String):void
Clears an invalidation flag.
FeathersControl
  
Creates and adds the offTrack sub-component and removes the old instance, if one exists.
ToggleSwitch
  
Creates and adds the onTrack sub-component and removes the old instance, if one exists.
ToggleSwitch
  
Creates and adds the thumb sub-component and removes the old instance, if one exists.
ToggleSwitch
 Inherited
draw():void
Override to customize layout and to adjust properties of children.
FeathersControl
 Inherited
focusInHandler(event:Event):void
Default event handler for FeathersEventType.FOCUS_IN that may be overridden in subclasses to perform additional actions when the component receives focus.
FeathersControl
 Inherited
focusOutHandler(event:Event):void
Default event handler for FeathersEventType.FOCUS_OUT that may be overridden in subclasses to perform additional actions when the component loses focus.
FeathersControl
 Inherited
The next style that is set will not be restricted.
FeathersControl
 Inherited
initialize():void
Called the first time that the UI control is added to the stage, and you should override this function to customize the initialization process.
FeathersControl
 Inherited
processStyleRestriction(key:Object):Boolean
Used by setters for properties that are considered "styles" to determine if the setter has been called directly on the component or from a style provider.
FeathersControl
 Inherited
Updates the focus indicator skin by showing or hiding it and adjusting its position and dimensions.
FeathersControl
 Inherited
saveMeasurements(width:Number, height:Number, minWidth:Number = 0, minHeight:Number = 0):Boolean
Saves the dimensions and minimum dimensions calculated for the component.
FeathersControl
 Inherited
setInvalidationFlag(flag:String):void
Sets an invalidation flag.
FeathersControl
 Inherited
setSizeInternal(width:Number, height:Number, canInvalidate:Boolean):Boolean
Sets the width and height of the control, with the option of invalidating or not.
FeathersControl
Events
 Event Summary Defined By
  ToggleSwitch
 InheritedDispatched after the component has validated for the first time.FeathersControl
 InheritedDispatched after initialize() has been called, but before the first time that draw() has been called.FeathersControl
 InheritedDispatched when the width or height of the control changes.FeathersControl
  Dispatched when the display object's state changes.ToggleSwitch
Styles
 StyleDefined By
  
A style name to add to the toggle switch's off label text renderer sub-component.
ToggleSwitch
  
A style name to add to the toggle switch's off track sub-component.
ToggleSwitch
  
A style name to add to the toggle switch's on label text renderer sub-component.
ToggleSwitch
  
A style name to add to the toggle switch's on track sub-component.
ToggleSwitch
  
A style name to add to the toggle switch's thumb sub-component.
ToggleSwitch
 Inherited
focusIndicatorSkin : DisplayObject
If this component supports focus, this optional skin will be displayed above the component when showFocus() is called.
FeathersControl
 Inherited
focusPadding : Number
Quickly sets all focus padding properties to the same value.
FeathersControl
 Inherited
The minimum space, in pixels, between the object's bottom edge and the bottom edge of the focus indicator skin.
FeathersControl
 Inherited
The minimum space, in pixels, between the object's left edge and the left edge of the focus indicator skin.
FeathersControl
 Inherited
The minimum space, in pixels, between the object's right edge and the right edge of the focus indicator skin.
FeathersControl
 Inherited
The minimum space, in pixels, between the object's top edge and the top edge of the focus indicator skin.
FeathersControl
  
The font styles used to display the off label's text when the toggle switch is disabled.
ToggleSwitch
  
offLabelFontStyles : TextFormat
The font styles used to display the off label's text.
ToggleSwitch
  
The font styles used to display the off label's text when the toggle switch is selected.
ToggleSwitch
  
offText : String
The text to display in the "off" label text renderer.
ToggleSwitch
  
The font styles used to display the on label's text when the toggle switch is disabled.
ToggleSwitch
  
onLabelFontStyles : TextFormat
The font styles used to display the on label's text.
ToggleSwitch
  
The font styles used to display the on label's text when the toggle switch is selected.
ToggleSwitch
  
onText : String
The text to display in the "on" label text renderer.
ToggleSwitch
  
paddingLeft : Number
The minimum space, in pixels, between the switch's left edge and the switch's content.
ToggleSwitch
  
paddingRight : Number
The minimum space, in pixels, between the switch's right edge and the switch's content.
ToggleSwitch
  
showLabels : Boolean
Determines if the labels should be drawn.
ToggleSwitch
  
showThumb : Boolean
Determines if the thumb should be displayed.
ToggleSwitch
  
The duration, in seconds, of the animation when the toggle switch is toggled and animates the position of the thumb.
ToggleSwitch
  
toggleEase : Object
The easing function used for toggle animations.
ToggleSwitch
  
Determines if the isSelected property of the thumb is updated to match the isSelected property of the toggle switch, if the class used to create the thumb implements the IToggle interface.
ToggleSwitch
  
Determines how the on and off track skins are positioned and sized.
ToggleSwitch
  
Determines how the on and off track skins are positioned and sized.
ToggleSwitch
Public Constants
 ConstantDefined By
  DEFAULT_CHILD_STYLE_NAME_OFF_LABEL : String = "feathers-toggle-switch-off-label"
[static] The default value added to the styleNameList of the "off label" text renderer.
ToggleSwitch
  DEFAULT_CHILD_STYLE_NAME_OFF_TRACK : String = "feathers-toggle-switch-off-track"
[static] The default value added to the styleNameList of the off track.
ToggleSwitch
  DEFAULT_CHILD_STYLE_NAME_ON_LABEL : String = "feathers-toggle-switch-on-label"
[static] The default value added to the styleNameList of the "on label" text renderer.
ToggleSwitch
  DEFAULT_CHILD_STYLE_NAME_ON_TRACK : String = "feathers-toggle-switch-on-track"
[static] The default value added to the styleNameList of the on track.
ToggleSwitch
  DEFAULT_CHILD_STYLE_NAME_THUMB : String = "feathers-toggle-switch-thumb"
[static] The default value added to the styleNameList of the thumb.
ToggleSwitch
 InheritedINVALIDATION_FLAG_ALL : String = "all"
[static] Flag to indicate that everything is invalid and should be redrawn.
FeathersControl
 InheritedINVALIDATION_FLAG_DATA : String = "data"
[static] Invalidation flag to indicate that the primary data displayed by the UI control has changed.
FeathersControl
 InheritedINVALIDATION_FLAG_FOCUS : String = "focus"
[static] Invalidation flag to indicate that the focus of the UI control has changed.
FeathersControl
 InheritedINVALIDATION_FLAG_LAYOUT : String = "layout"
[static] Invalidation flag to indicate that the layout of the UI control has changed.
FeathersControl
 InheritedINVALIDATION_FLAG_SCROLL : String = "scroll"
[static] Invalidation flag to indicate that the scroll position of the UI control has changed.
FeathersControl
 InheritedINVALIDATION_FLAG_SELECTED : String = "selected"
[static] Invalidation flag to indicate that the selection of the UI control has changed.
FeathersControl
 InheritedINVALIDATION_FLAG_SIZE : String = "size"
[static] Invalidation flag to indicate that the dimensions of the UI control have changed.
FeathersControl
 InheritedINVALIDATION_FLAG_SKIN : String = "skin"
[static] Invalidation flag to indicate that the skin of the UI control has changed.
FeathersControl
 InheritedINVALIDATION_FLAG_STATE : String = "state"
[static] Invalidation flag to indicate that the state has changed.
FeathersControl
 InheritedINVALIDATION_FLAG_STYLES : String = "styles"
[static] Invalidation flag to indicate that the styles or visual appearance of the UI control has changed.
FeathersControl
Property Detail
baselineproperty
baseline:Number  [read-only]

Returns the text baseline measurement, in pixels.


Implementation
    public function get baseline():Number
currentStateproperty 
currentState:String  [read-only]

The current state of the toggle switch.


Implementation
    public function get currentState():String

See also

defaultLabelPropertiesproperty 
defaultLabelProperties:Object

An object that stores properties for the toggle switch's label text renderers when the toggle switch is enabled, and the properties will be passed down to the text renderers when the toggle switch validates. The available properties depend on which ITextRenderer implementation is returned by labelFactory (possibly onLabelFactory or offLabelFactory instead). Refer to feathers.core.ITextRenderer for a list of available text renderer implementations.

In the following example, the toggle switch's default label properties are updated (this example assumes that the label text renderers are of type TextFieldTextRenderer):

toggle.defaultLabelProperties.textFormat = new TextFormat( "Source Sans Pro", 16, 0x333333 );
toggle.defaultLabelProperties.embedFonts = true;

The default value is null.


Implementation
    public function get defaultLabelProperties():Object
    public function set defaultLabelProperties(value:Object):void

See also

disabledLabelPropertiesproperty 
disabledLabelProperties:Object

An object that stores properties for the toggle switch's label text renderers when the toggle switch is disabled, and the properties will be passed down to the text renderers when the toggle switch validates. The available properties depend on which ITextRenderer implementation is returned by labelFactory (possibly onLabelFactory or offLabelFactory instead). Refer to feathers.core.ITextRenderer for a list of available text renderer implementations.

In the following example, the toggle switch's disabled label properties are updated (this example assumes that the label text renderers are of type TextFieldTextRenderer):

toggle.disabledLabelProperties.textFormat = new TextFormat( "Source Sans Pro", 16, 0x333333 );
toggle.disabledLabelProperties.embedFonts = true;

The default value is null.


Implementation
    public function get disabledLabelProperties():Object
    public function set disabledLabelProperties(value:Object):void

See also

globalStyleProviderproperty 
public static var globalStyleProvider:IStyleProvider

The default IStyleProvider for all ToggleSwitch components.

The default value is null.

See also

isSelectedproperty 
isSelected:Boolean

Indicates if the toggle switch is selected (ON) or not (OFF).

In the following example, the toggle switch is selected:

toggle.isSelected = true;

The default value is false.


Implementation
    public function get isSelected():Boolean
    public function set isSelected(value:Boolean):void

See also

labelFactoryproperty 
labelFactory:Function

A function used to instantiate the toggle switch's label text renderer sub-components, if specific factories for those label text renderers are not provided. The label text renderers must be instances of ITextRenderer. This factory can be used to change properties of the label text renderers when they are first created. For instance, if you are skinning Feathers components without a theme, you might use this factory to style the label text renderers.

The factory should have the following function signature:

function():ITextRenderer

In the following example, the toggle switch uses a custom label factory:

toggle.labelFactory = function():ITextRenderer
{
    return new TextFieldTextRenderer();
}

The default value is null.


Implementation
    public function get labelFactory():Function
    public function set labelFactory(value:Function):void

See also

offLabelFactoryproperty 
offLabelFactory:Function

A function used to instantiate the toggle switch's off label text renderer sub-component. The off label text renderer must be an instance of ITextRenderer. This factory can be used to change properties of the off label text renderer when it is first created. For instance, if you are skinning Feathers components without a theme, you might use this factory to style the off label text renderer.

If an offLabelFactory is not provided, the default labelFactory will be used.

The factory should have the following function signature:

function():ITextRenderer

In the following example, the toggle switch uses a custom on label factory:

toggle.offLabelFactory = function():ITextRenderer
{
    return new TextFieldTextRenderer();
}

The default value is null.


Implementation
    public function get offLabelFactory():Function
    public function set offLabelFactory(value:Function):void

See also

offLabelPropertiesproperty 
offLabelProperties:Object

An object that stores properties for the toggle switch's "off" label text renderer, and the properties will be passed down to the text renderer when the toggle switch validates. If null, then defaultLabelProperties is used instead.

The available properties depend on which ITextRenderer implementation is returned by labelFactory (possibly offLabelFactory instead). Refer to feathers.core.ITextRenderer for a list of available text renderer implementations.

In the following example, the toggle switch's off label properties are updated (this example assumes that the off label text renderer is a TextFieldTextRenderer):

toggle.offLabelProperties.textFormat = new TextFormat( "Source Sans Pro", 16, 0x333333 );
toggle.offLabelProperties.embedFonts = true;

The default value is null.


Implementation
    public function get offLabelProperties():Object
    public function set offLabelProperties(value:Object):void

See also

offLabelStyleNameproperty 
protected var offLabelStyleName:String = "feathers-toggle-switch-off-label"

The value added to the styleNameList of the off label text renderer. This variable is protected so that sub-classes can customize the off label text renderer style name in their constructors instead of using the default style name defined by DEFAULT_CHILD_STYLE_NAME_OFF_LABEL.

To customize the "off" label text renderer style name without subclassing, see customOffLabelStyleName.

See also

offTextRendererproperty 
protected var offTextRenderer:ITextRenderer

The "off" text renderer sub-component.

For internal use in subclasses.

See also

offTrackproperty 
protected var offTrack:DisplayObject

The "off" track sub-component.

For internal use in subclasses.

See also

offTrackFactoryproperty 
offTrackFactory:Function

A function used to generate the toggle switch's "off" track sub-component. The "off" track must be an instance of BasicButton (or a subclass). This factory can be used to change properties on the "off" track when it is first created. For instance, if you are skinning Feathers components without a theme, you might use this factory to set skins and other styles on the "off" track.

The function should have the following signature:

function():BasicButton

In the following example, a custom off track factory is passed to the toggle switch:

toggle.offTrackFactory = function():BasicButton
{
    var offTrack:BasicButton = new BasicButton();
    offTrack.defaultSkin = new Image( texture );
    return offTrack;
};

The default value is null.


Implementation
    public function get offTrackFactory():Function
    public function set offTrackFactory(value:Function):void

See also

offTrackPropertiesproperty 
offTrackProperties:Object

An object that stores properties for the toggle switch's "off" track, and the properties will be passed down to the "off" track when the toggle switch validates. For a list of available properties, refer to feathers.controls.BasicButton.

If the subcomponent has its own subcomponents, their properties can be set too, using attribute @ notation. For example, to set the skin on the thumb which is in a SimpleScrollBar, which is in a List, you can use the following syntax:

list.verticalScrollBarProperties.@thumbProperties.defaultSkin = new Image(texture);

Setting properties in a offTrackFactory function instead of using offTrackProperties will result in better performance.

In the following example, the toggle switch's off track properties are updated:

toggle.offTrackProperties.defaultSkin = new Image( texture );

The default value is null.


Implementation
    public function get offTrackProperties():Object
    public function set offTrackProperties(value:Object):void

See also

offTrackStyleNameproperty 
protected var offTrackStyleName:String = "feathers-toggle-switch-off-track"

The value added to the styleNameList of the off track. This variable is protected so that sub-classes can customize the off track style name in their constructors instead of using the default style name defined by DEFAULT_CHILD_STYLE_NAME_OFF_TRACK.

To customize the off track style name without subclassing, see customOffTrackStyleName.

See also

onLabelFactoryproperty 
onLabelFactory:Function

A function used to instantiate the toggle switch's on label text renderer sub-component. The on label text renderer must be an instance of ITextRenderer. This factory can be used to change properties of the on label text renderer when it is first created. For instance, if you are skinning Feathers components without a theme, you might use this factory to style the on label text renderer.

If an onLabelFactory is not provided, the default labelFactory will be used.

The factory should have the following function signature:

function():ITextRenderer

In the following example, the toggle switch uses a custom on label factory:

toggle.onLabelFactory = function():ITextRenderer
{
    return new TextFieldTextRenderer();
}

The default value is null.


Implementation
    public function get onLabelFactory():Function
    public function set onLabelFactory(value:Function):void

See also

onLabelPropertiesproperty 
onLabelProperties:Object

An object that stores properties for the toggle switch's "on" label text renderer, and the properties will be passed down to the text renderer when the toggle switch validates. If null, then defaultLabelProperties is used instead.

The available properties depend on which ITextRenderer implementation is returned by labelFactory (possibly onLabelFactory instead). Refer to feathers.core.ITextRenderer for a list of available text renderer implementations.

In the following example, the toggle switch's on label properties are updated (this example assumes that the on label text renderer is a TextFieldTextRenderer):

toggle.onLabelProperties.textFormat = new TextFormat( "Source Sans Pro", 16, 0x333333 );
toggle.onLabelProperties.embedFonts = true;

The default value is null.


Implementation
    public function get onLabelProperties():Object
    public function set onLabelProperties(value:Object):void

See also

onLabelStyleNameproperty 
protected var onLabelStyleName:String = "feathers-toggle-switch-on-label"

The value added to the styleNameList of the off label text renderer. This variable is protected so that sub-classes can customize the on label text renderer style name in their constructors instead of using the default style name defined by DEFAULT_CHILD_STYLE_NAME_ON_LABEL.

To customize the "on" label text renderer style name without subclassing, see customOnLabelStyleName.

See also

onTextRendererproperty 
protected var onTextRenderer:ITextRenderer

The "on" text renderer sub-component.

See also

onTrackproperty 
protected var onTrack:DisplayObject

The "on" track sub-component.

For internal use in subclasses.

See also

onTrackFactoryproperty 
onTrackFactory:Function

A function used to generate the toggle switch's "on" track sub-component. The "on" track must be an instance of BasicButton (or a subclass). This factory can be used to change properties on the "on" track when it is first created. For instance, if you are skinning Feathers components without a theme, you might use this factory to set skins and other styles on the "on" track.

The function should have the following signature:

function():BasicButton

In the following example, a custom on track factory is passed to the toggle switch:

toggle.onTrackFactory = function():BasicButton
{
    var onTrack:BasicButton = new BasicButton();
    onTrack.defaultSkin = new Image( texture );
    return onTrack;
};

The default value is null.


Implementation
    public function get onTrackFactory():Function
    public function set onTrackFactory(value:Function):void

See also

onTrackPropertiesproperty 
onTrackProperties:Object

An object that stores properties for the toggle switch's "on" track, and the properties will be passed down to the "on" track when the toggle switch validates. For a list of available properties, refer to feathers.controls.BasicButton.

If the subcomponent has its own subcomponents, their properties can be set too, using attribute @ notation. For example, to set the skin on the thumb which is in a SimpleScrollBar, which is in a List, you can use the following syntax:

list.verticalScrollBarProperties.@thumbProperties.defaultSkin = new Image(texture);

Setting properties in a onTrackFactory function instead of using onTrackProperties will result in better performance.

In the following example, the toggle switch's on track properties are updated:

toggle.onTrackProperties.defaultSkin = new Image( texture );

The default value is null.


Implementation
    public function get onTrackProperties():Object
    public function set onTrackProperties(value:Object):void

See also

onTrackStyleNameproperty 
protected var onTrackStyleName:String = "feathers-toggle-switch-on-track"

The value added to the styleNameList of the on track. This variable is protected so that sub-classes can customize the on track style name in their constructors instead of using the default style name defined by DEFAULT_CHILD_STYLE_NAME_ON_TRACK.

To customize the on track style name without subclassing, see customOnTrackStyleName.

See also

thumbproperty 
protected var thumb:DisplayObject

The thumb sub-component.

For internal use in subclasses.

See also

thumbFactoryproperty 
thumbFactory:Function

A function used to generate the toggle switch's thumb sub-component. The thumb must be an instance of BasicButton (or a subclass). This factory can be used to change properties on the thumb when it is first created. For instance, if you are skinning Feathers components without a theme, you might use thumbFactory to set skins and other styles on the thumb.

The function should have the following signature:

function():BasicButton

In the following example, a custom thumb factory is passed to the toggle switch:

toggle.thumbFactory = function():BasicButton
{
    var button:BasicButton = new BasicButton();
    button.defaultSkin = new Image( texture );
    return button;
};

The default value is null.


Implementation
    public function get thumbFactory():Function
    public function set thumbFactory(value:Function):void

See also

thumbPropertiesproperty 
thumbProperties:Object

An object that stores properties for the toggle switch's thumb sub-component, and the properties will be passed down to the thumb when the toggle switch validates. For a list of available properties, refer to feathers.controls.BasicButton.

If the subcomponent has its own subcomponents, their properties can be set too, using attribute @ notation. For example, to set the skin on the thumb which is in a SimpleScrollBar, which is in a List, you can use the following syntax:

list.verticalScrollBarProperties.@thumbProperties.defaultSkin = new Image(texture);

Setting properties in a thumbFactory function instead of using thumbProperties will result in better performance.

In the following example, the toggle switch's thumb properties are updated:

toggle.thumbProperties.defaultSkin = new Image( texture );

The default value is null.


Implementation
    public function get thumbProperties():Object
    public function set thumbProperties(value:Object):void

See also

thumbStyleNameproperty 
protected var thumbStyleName:String = "feathers-toggle-switch-thumb"

The value added to the styleNameList of the thumb. This variable is protected so that sub-classes can customize the thumb style name in their constructors instead of using the default stylename defined by DEFAULT_CHILD_STYLE_NAME_THUMB.

To customize the thumb style name without subclassing, see customThumbStyleName.

See also

Constructor Detail
ToggleSwitch()Constructor
public function ToggleSwitch()

Constructor.

Method Detail
autoSizeIfNeeded()method
protected function autoSizeIfNeeded():Boolean

If the component's dimensions have not been set explicitly, it will measure its content and determine an ideal size for itself. If the explicitWidth or explicitHeight member variables are set, those value will be used without additional measurement. If one is set, but not the other, the dimension with the explicit value will not be measured, but the other non-explicit dimension will still need measurement.

Calls saveMeasurements() to set up the actualWidth and actualHeight member variables used for layout.

Meant for internal use, and subclasses may override this function with a custom implementation.

Returns
Boolean
createOffTrack()method 
protected function createOffTrack():void

Creates and adds the offTrack sub-component and removes the old instance, if one exists. If the off track is not needed, it will not be created.

Meant for internal use, and subclasses may override this function with a custom implementation.

See also

createOnTrack()method 
protected function createOnTrack():void

Creates and adds the onTrack sub-component and removes the old instance, if one exists.

Meant for internal use, and subclasses may override this function with a custom implementation.

See also

createThumb()method 
protected function createThumb():void

Creates and adds the thumb sub-component and removes the old instance, if one exists.

Meant for internal use, and subclasses may override this function with a custom implementation.

See also

getOffLabelFontStylesForState()method 
public function getOffLabelFontStylesForState(state:String):TextFormat

Gets the font styles to be used to display the toggle switch's off label text when the toggle switch's currentState property matches the specified state value.

If font styles are not defined for a specific state, returns null.

Parameters

state:String

Returns
TextFormat

See also

getOnLabelFontStylesForState()method 
public function getOnLabelFontStylesForState(state:String):TextFormat

Gets the font styles to be used to display the toggle switch's on label text when the toggle switch's currentState property matches the specified state value.

If font styles are not defined for a specific state, returns null.

Parameters

state:String

Returns
TextFormat

See also

setOffLabelFontStylesForState()method 
public function setOffLabelFontStylesForState(state:String, format:TextFormat):void

Sets the font styles to be used to display the toggle switch's off label text when the toggle switch's currentState property matches the specified state value.

If font styles are not defined for a specific state, the value of the offLabelFontStyles property will be used instead.

Note: if the text renderer has been customized with advanced font formatting, it may override the values specified with setOffLabelFontStylesForState() and properties like offLabelFontStyles and offLabelDisabledFontStyles.

Parameters

state:String
 
format:TextFormat

See also

setOnLabelFontStylesForState()method 
public function setOnLabelFontStylesForState(state:String, format:TextFormat):void

Sets the font styles to be used to display the toggle switch's on label text when the toggle switch's currentState property matches the specified state value.

If font styles are not defined for a specific state, the value of the onLabelFontStyles property will be used instead.

Note: if the text renderer has been customized with advanced font formatting, it may override the values specified with setOnLabelFontStylesForState() and properties like onLabelFontStyles and onLabelDisabledFontStyles.

Parameters

state:String
 
format:TextFormat

See also

setSelectionWithAnimation()method 
public function setSelectionWithAnimation(isSelected:Boolean):void

Changes the isSelected property, but animates the thumb to the new position, as if the user tapped the toggle switch.

Parameters

isSelected:Boolean

See also

Event Detail
change Event
Event Object Type: starling.events.Event

Dispatched when the selection changes.

The properties of the event object have the following values:

PropertyValue
bubblesfalse
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.
datanull
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.

See also

stateChange Event  
Event Object Type: starling.events.Event
Event.type property = feathers.events.FeathersEventType.STATE_CHANGE

Dispatched when the display object's state changes.

The properties of the event object have the following values:

PropertyValue
bubblesfalse
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.
datanull
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.

The FeathersEventType.STATE_CHANGE event type is used by Feathers classes that implement the IStateContext interface.

See also

Style Detail
trackScaleModestyle
trackScaleMode:String

Determines how the on and off track skins are positioned and sized.

In the following example, the toggle switch's track scale is customized:

toggle.trackScaleMode = TrackScaleMode.EXACT_FIT;

The default value is feathers.controls.TrackScaleMode.DIRECTIONAL.

See also

trackLayoutModestyle 
trackLayoutMode:String

Determines how the on and off track skins are positioned and sized.

In the following example, the toggle switch's track layout mode is updated to use two tracks:

toggle.trackLayoutMode = TrackLayoutMode.SPLIT;

The default value is feathers.controls.TrackLayoutMode.SINGLE.

See also

toggleThumbSelectionstyle 
toggleThumbSelection:Boolean

Determines if the isSelected property of the thumb is updated to match the isSelected property of the toggle switch, if the class used to create the thumb implements the IToggle interface. Useful for skinning to provide a different appearance for the thumb based on whether the toggle switch is selected or not.

In the following example, the thumb selection is toggled:

toggle.toggleThumbSelection = true;

The default value is false.

See also

toggleEasestyle 
toggleEase:Object

The easing function used for toggle animations.

In the following example, the easing function used by the toggle switch's thumb animation is updated:

toggle.toggleEase = Transitions.EASE_IN_OUT;

The default value is starling.animation.Transitions.EASE_OUT.

See also

toggleDurationstyle 
toggleDuration:Number

The duration, in seconds, of the animation when the toggle switch is toggled and animates the position of the thumb.

In the following example, the duration of the toggle switch thumb animation is updated:

toggle.toggleDuration = 0.5;

The default value is 0.15.

showThumbstyle 
showThumb:Boolean

Determines if the thumb should be displayed. This stops interaction while still displaying the background.

In the following example, the toggle switch's thumb is hidden:

toggle.showThumb = false;

The default value is true.

showLabelsstyle 
showLabels:Boolean

Determines if the labels should be drawn. The onTrackSkin and offTrackSkin backgrounds may include the text instead.

In the following example, the toggle switch's labels are hidden:

toggle.showLabels = false;

The default value is true.

paddingRightstyle 
paddingRight:Number

The minimum space, in pixels, between the switch's right edge and the switch's content.

In the following example, the toggle switch's right padding is set to 20 pixels:

toggle.paddingRight = 20;

The default value is 0.

See also

paddingLeftstyle 
paddingLeft:Number

The minimum space, in pixels, between the switch's left edge and the switch's content.

In the following example, the toggle switch's left padding is set to 20 pixels:

toggle.paddingLeft = 20;

The default value is 0.

See also

offTextstyle 
offText:String

The text to display in the "off" label text renderer.

In the following example, the toggle switch's off label text is updated:

toggle.offText = "off";

The default value is "OFF".

See also

offLabelSelectedFontStylesstyle 
offLabelSelectedFontStyles:TextFormat

The font styles used to display the off label's text when the toggle switch is selected.

In the following example, the off label's selected font styles are customized:

toggle.offLabelSelectedFontStyles = new TextFormat( "Helvetica", 20, 0xff0000 );

Note: The starling.text.TextFormat class defines a number of common font styles, but the text renderer being used may support a larger number of ways to be customized. Use the offLabelFactory to set more advanced styles on the text renderer.

The default value is null.

See also

offLabelFontStylesstyle 
offLabelFontStyles:TextFormat

The font styles used to display the off label's text.

In the following example, the off label's font styles are customized:

toggle.offLabelFontStyles = new TextFormat( "Helvetica", 20, 0xcc0000 );

Note: The starling.text.TextFormat class defines a number of common font styles, but the text renderer being used may support a larger number of ways to be customized. Use the offLabelFactory to set more advanced styles.

The default value is null.

See also

offLabelDisabledFontStylesstyle 
offLabelDisabledFontStyles:TextFormat

The font styles used to display the off label's text when the toggle switch is disabled.

In the following example, the off labels' disabled font styles are customized:

toggle.offLabelDisabledFontStyles = new TextFormat( "Helvetica", 20, 0x999999 );

Note: The starling.text.TextFormat class defines a number of common font styles, but the text renderer being used may support a larger number of ways to be customized. Use the offLabelFactory to set more advanced styles on the text renderer.

The default value is null.

See also

onTextstyle 
onText:String

The text to display in the "on" label text renderer.

In the following example, the toggle switch's "on" label text is updated:

toggle.onText = "on";

The default value is "ON".

See also

onLabelSelectedFontStylesstyle 
onLabelSelectedFontStyles:TextFormat

The font styles used to display the on label's text when the toggle switch is selected.

In the following example, the on label's selected font styles are customized:

toggle.onLabelSelectedFontStyles = new TextFormat( "Helvetica", 20, 0xff0000 );

Note: The starling.text.TextFormat class defines a number of common font styles, but the text renderer being used may support a larger number of ways to be customized. Use the onLabelFactory to set more advanced styles on the text renderer.

The default value is null.

See also

onLabelFontStylesstyle 
onLabelFontStyles:TextFormat

The font styles used to display the on label's text.

In the following example, the on label's font styles are customized:

toggle.onLabelFontStyles = new TextFormat( "Helvetica", 20, 0xcc0000 );

Note: The starling.text.TextFormat class defines a number of common font styles, but the text renderer being used may support a larger number of ways to be customized. Use the onLabelFactory to set more advanced styles.

The default value is null.

See also

onLabelDisabledFontStylesstyle 
onLabelDisabledFontStyles:TextFormat

The font styles used to display the on label's text when the toggle switch is disabled.

In the following example, the on labels' disabled font styles are customized:

toggle.onLabelDisabledFontStyles = new TextFormat( "Helvetica", 20, 0x999999 );

Note: The starling.text.TextFormat class defines a number of common font styles, but the text renderer being used may support a larger number of ways to be customized. Use the onLabelFactory to set more advanced styles on the text renderer.

The default value is null.

See also

customThumbStyleNamestyle 
customThumbStyleName:String

A style name to add to the toggle switch's thumb sub-component. Typically used by a theme to provide different styles to different toggle switches.

In the following example, a custom thumb style name is passed to the toggle switch:

toggle.customThumbStyleName = "my-custom-thumb";

In your theme, you can target this sub-component style name to provide different styles than the default:

getStyleProviderForClass( Button ).setFunctionForStyleName( "my-custom-thumb", setCustomThumbStyles );

The default value is null.

See also

customOffTrackStyleNamestyle 
customOffTrackStyleName:String

A style name to add to the toggle switch's off track sub-component. Typically used by a theme to provide different styles to different toggle switches.

In the following example, a custom off track style name is passed to the toggle switch:

toggle.customOffTrackStyleName = "my-custom-off-track";

In your theme, you can target this sub-component style name to provide different styles than the default:

getStyleProviderForClass( Button ).setFunctionForStyleName( "my-custom-off-track", setCustomOffTrackStyles );

The default value is null.

See also

customOffLabelStyleNamestyle 
customOffLabelStyleName:String

A style name to add to the toggle switch's off label text renderer sub-component. Typically used by a theme to provide different styles to different toggle switches.

In the following example, a custom off label style name is passed to the toggle switch:

toggle.customOffLabelStyleName = "my-custom-toggle-off-label";

In your theme, you can target this sub-component style name to provide different styles than the default:

getStyleProviderForClass( BitmapFontTextRenderer ).setFunctionForStyleName( "my-custom-toggle-off-label", setCustomToggleSwitchOffLabelStyles );

The default value is null.

See also

customOnTrackStyleNamestyle 
customOnTrackStyleName:String

A style name to add to the toggle switch's on track sub-component. Typically used by a theme to provide different styles to different toggle switches.

In the following example, a custom on track style name is passed to the toggle switch:

toggle.customOnTrackStyleName = "my-custom-on-track";

In your theme, you can target this sub-component style name to provide different styles than the default:

getStyleProviderForClass( Button ).setFunctionForStyleName( "my-custom-on-track", setCustomOnTrackStyles );

The default value is null.

See also

customOnLabelStyleNamestyle 
customOnLabelStyleName:String

A style name to add to the toggle switch's on label text renderer sub-component. Typically used by a theme to provide different styles to different buttons.

In the following example, a custom on label style name is passed to the toggle switch:

toggle.customOnLabelStyleName = "my-custom-toggle-on-label";

In your theme, you can target this sub-component style name to provide different styles than the default:

getStyleProviderForClass( BitmapFontTextRenderer ).setFunctionForStyleName( "my-custom-toggle-on-label", setCustomToggleSwitchOnLabelStyles );

The default value is null.

See also

Constant Detail
DEFAULT_CHILD_STYLE_NAME_OFF_LABELConstant
public static const DEFAULT_CHILD_STYLE_NAME_OFF_LABEL:String = "feathers-toggle-switch-off-label"

The default value added to the styleNameList of the "off label" text renderer.

Note: the "off label" text renderer is not a feathers.controls.Label. It is an instance of one of the ITextRenderer implementations.

See also

DEFAULT_CHILD_STYLE_NAME_OFF_TRACKConstant 
public static const DEFAULT_CHILD_STYLE_NAME_OFF_TRACK:String = "feathers-toggle-switch-off-track"

The default value added to the styleNameList of the off track.

See also

DEFAULT_CHILD_STYLE_NAME_ON_LABELConstant 
public static const DEFAULT_CHILD_STYLE_NAME_ON_LABEL:String = "feathers-toggle-switch-on-label"

The default value added to the styleNameList of the "on label" text renderer.

Note: the "on label" text renderer is not a feathers.controls.Label. It is an instance of one of the ITextRenderer implementations.

See also

DEFAULT_CHILD_STYLE_NAME_ON_TRACKConstant 
public static const DEFAULT_CHILD_STYLE_NAME_ON_TRACK:String = "feathers-toggle-switch-on-track"

The default value added to the styleNameList of the on track.

See also

DEFAULT_CHILD_STYLE_NAME_THUMBConstant 
public static const DEFAULT_CHILD_STYLE_NAME_THUMB:String = "feathers-toggle-switch-thumb"

The default value added to the styleNameList of the thumb.

See also