qnx.fuse.ui.buttons.ToggleSwitch

ToggleSwitch

Properties | Methods | Events | Examples


Packageqnx.fuse.ui.buttons
Classpublic class ToggleSwitch
InheritanceToggleSwitch Inheritance UIComponent Inheritance flash.display.MovieClip

The ToggleSwitch represents a button that has one of two states indicating the component is "ON" or "OFF".

You can touch and drag the toggle switch to change state, or you can tap the track or the background of the toggle switch to toggle between states.

A toggle switch is comprised of a track, thumb, fill, and two text labels:

A toggle switch.



Class information:
BlackBerry 10 Version:   10.0.0

View the examples

See also

Button.toggle



Public Properties

 PropertyDefined By
 InheritedcontextActions : Vector.<ActionSet>
Gets or Sets a Vector of ActionSet objects.
UIComponent
 InheritedcontextMultiSelectText : String
Gets or Sets a String to be displayed when showing the Multi Select Context Menu.
UIComponent
 InheritedcurrentTheme : String
[read-only] Returns the current theme this component is styled with.
UIComponent
  defaultLabel : String
Gets or sets the text of the default label, or Off label.
ToggleSwitch
 InheritedexplicitHeight : Number
[read-only] Returns the explicit height (actual height, in pixels) of the UI component.
UIComponent
 InheritedexplicitWidth : Number
[read-only] Returns the explicit width (actual width, in pixels) of the UI component.
UIComponent
 Inheritedid : String
The id is a name for the component that can be used in CSS using the # selector.
UIComponent
 InheritedincludeInLayout : Boolean
Specifies whether or not the component should be included in its parent container's layout.
UIComponent
  labelPadding : int
Gets or sets the padding on either side of the labels.
ToggleSwitch
 InheritedlayoutData : Object
Gets or sets the layoutData.
UIComponent
 Inheritedlocale : String
Gets or sets the current locale of the component.
UIComponent
 InheritedminHeight : Number
Gets or sets the minimum preferred height of the control.
UIComponent
 InheritedminWidth : Number
Gets or sets the minimum preferred width of the control.
UIComponent
  selected : Boolean
Gets or sets the value of the switch (the position of the thumb).
ToggleSwitch
  selectedLabel : String
Gets or sets the text of the selected label, or On label.
ToggleSwitch
 InheritedstyleChildren : Boolean
Allows you to style the children of this component with CSS.
UIComponent

Protected Properties

 PropertyDefined By
 InheritedaccessibilityImplimentationClass : Class
UIComponent
  cssID : String
[override] [read-only] Returns the CSS ID of the component.
ToggleSwitch
 InheritedexplicitLocale : Boolean
Set to true when the locale property has been set externally.
UIComponent
 InheritedinternalID : String
The Component's Id used for styling.
UIComponent
 InheritedlongPressEnabled : Boolean
Specifies whether the UIComponent can detect a long press.
UIComponent

Public Methods

 MethodDefined By
  
Constructs a ToggleSwitch instance.
ToggleSwitch
 Inherited
Cancels a long press from occuring on the component.
UIComponent
 Inherited
childChanged(resizedChild:DisplayObject = null):Boolean
Notifies the UIComponent that one or more of its children has changed in a manner that may affect this object's layout.
UIComponent
 Inherited
destroy():void
Call this method when you want to have your object collected by the garbage collector.
UIComponent
 Inherited
Returns the CSS selector for the object, composing it from its position in the display hierarchy and an optional ID selector.
UIComponent
 Inherited
Returns the size options for the given control.
UIComponent
  
Returns the TextFormat object for a specified state.
ToggleSwitch
 Inherited
Calling this method results in a call to the components validateDisplayList() method before the display list is rendered.
UIComponent
 Inherited
Calling this method results in a call to the components validateProperties() method before the display list is rendered.
UIComponent
 Inherited
measure(availableWidth:Number, availableHeight:Number):LayoutMeasurement
This method calls doMeasure() in order to calculate the preferred size of the control.
UIComponent
 Inherited
setActualSize(w:Number, h:Number):void
Sets the width and height of the object without setting the explicitWidth and explicitHeight.
UIComponent
 Inherited
setLayoutBounds(bounds:Rectangle):void
Sets the receiver's size and location to the rectangular area specified by the arguments.
UIComponent
 Inherited
setPosition(x:Number, y:Number):void
Sets the x and y position of the component.
UIComponent
  
setTextFormatForState(format:TextFormat, stateToModify:String):void
Sets the TextFormat object for the label for a given state.
ToggleSwitch
  
setThumbSkin(skin:Object):void
Sets the skin for the ToggleSwitch thumb button.
ToggleSwitch
  
setTrackSkin(skin:Object):void
Sets the skin for the track of the toggle switch.
ToggleSwitch
 Inherited
updateDefaultLocale(updateChildren:Boolean = true):void
Updates the locale property to be the same as the locale of the device.
UIComponent
 Inherited
Lets a component that contains text know that it should update its font formats as the font settings have changed.
UIComponent
 Inherited
Validates the display list of the component by calling the updateDisplayList().
UIComponent
 Inherited
Validates the component immediately by calling validateProperties(), validateSizes(), and validateDisplayList() if necessary.
UIComponent
 Inherited
Validates the properties of the component by calling the commitProperties() method.
UIComponent

Protected Methods

 MethodDefined By
 Inherited
allowShowContextMenu(target:IEventDispatcher):Boolean
When the user presses on the component this method is called with the object that dispatched the event.
UIComponent
 Inherited
Process properties of the component.
UIComponent
 Inherited
Process the state of the component.
UIComponent
 Inherited
Style the component after the style has changed.
UIComponent
 Inherited
doMeasure(availableWidth:Number, availableHeight:Number):LayoutMeasurement
Performs a measurement on the control, and returns a LayoutMeasurement instance containing the available width and height within the layout.
UIComponent
 Inherited
excemptFromCSSStyling(target:*, property:String = null):void
Exempts a property on an object from being styled by CSS.
UIComponent
 Inherited
flushCache():void
Invoked as part of parentLayoutChanged.
UIComponent
 Inherited
getStyleApplier():Function
A style applier is a method that gets called every time a property from the stylesheet should be applied to the component.
UIComponent
 Inherited
onAdded():void
Called when the instance is added to the stage.
UIComponent
 Inherited
Is called when a user is no longer long pressing on the component.
UIComponent
 Inherited
Is called when a user long presses on the component.
UIComponent
 Inherited
onRemoved():void
Called when the instance is removed from the stage.
UIComponent
 Inherited
Invalidates the parent's size and display list if includeInLayout property is set to true.
UIComponent
 Inherited
Calling this function will refresh the ContextMenu with whatever actions were set by contextActions.
UIComponent
 Inherited
Shows the context menu if there are contextActions associated with the control.
UIComponent
 Inherited
styleState():void
Style the component after state has changed.
UIComponent
 Inherited
updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
Sets the size and position of the children of the component.
UIComponent

Events

 Event Summary Defined By
 InheritedDispatched when an action in the Context Menu is selected.UIComponent
 InheritedDispatched when the Context Menu has closed to the DISMISSED state.UIComponent
 InheritedDispatched when the ContextMenu is closing to the DISMISSED state.UIComponent
 InheritedDispatched when the Context Menu has opened to the PEEK or EXPANDED state.UIComponent
 InheritedDispatched when the ContextMenu is opening from the DISMISSED state.UIComponent
 InheritedDispatched when the CrossCut multiselect has been canceled.UIComponent
  Dispatches a select event when the selection of the control changes.ToggleSwitch

Property Detail

cssID


cssID:String  [read-only]
[override]

Returns the CSS ID of the component. The CSS ID is used for identifying the type of component in CSS.

The default value is ToggleSwitch.


Implementation

protected function get cssID():String

defaultLabel


defaultLabel:String

Gets or sets the text of the default label, or Off label.

The control will attempt to update this value when the device changes languages. In order for this to happen, your application must link against the QNXDevice.ane.

The default value is "Off" when the device language is set to English and "O" for non-English languages.


Implementation

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

labelPadding


labelPadding:int

Gets or sets the padding on either side of the labels.


Implementation

public function get labelPadding():int
public function set labelPadding(value:int):void

selected


selected:Boolean

Gets or sets the value of the switch (the position of the thumb).

true for On, selected, false for Off, unselected.


Implementation

public function get selected():Boolean
public function set selected(value:Boolean):void

selectedLabel


selectedLabel:String

Gets or sets the text of the selected label, or On label.

The control will attempt to update this value when the device changes languages. In order for this to happen, your application must link against the QNXDevice.ane.

The default value is "On" when the device language is set to English and "I" for non-English languages.


Implementation

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

Constructor Detail

ToggleSwitch()


public function ToggleSwitch()

Constructs a ToggleSwitch instance.

Method Detail

getTextFormatForState()


public function getTextFormatForState(state:String):TextFormat

Returns the TextFormat object for a specified state.

Parameters

state:String — The state for the TextFormat object to return. Valid states are:
  • SkinStates.UP
  • SkinStates.DOWN
  • SkinStates.SELECTED
  • SkinStates.DISABLED
  • SkinStates.DISABLED_SELECTED

Returns

TextFormat — The TextFormat object for the specified state.

See also

setTextFormatForState()
SkinStates

setTextFormatForState()


public function setTextFormatForState(format:TextFormat, stateToModify:String):void

Sets the TextFormat object for the label for a given state. Valid states are:

  • SkinStates.UP
  • SkinStates.DOWN
  • SkinStates.SELECTED
  • SkinStates.DISABLED
  • SkinStates.DISABLED_SELECTED
If the values of the supplied TextFormat are equal to the TextFormat that currently exists for the style, no change occurs and the LabelButton is not redrawn. Setting a TextFormat through this method will replace all styles that are defined in the ThemeGlobals CSS, so use this only if you want to replace all the default styles for the state.

Parameters

format:TextFormat — The TextFormat to set.
stateToModify:String — The state for which to change the TextFormat.

See also

SkinStates
getTextFormatForState()

setThumbSkin()


public function setThumbSkin(skin:Object):void

Sets the skin for the ToggleSwitch thumb button. The thumb is the button that the user moves along the track.

You can pass in a qualified class name String, or the actual class. In either instance the class that is used must implement the ISkin interface.

Note: Do not pass in an instance of a skin class. This may cause unexpected behavior.

Parameters

skin:Object — The button skin to set.

setTrackSkin()


public function setTrackSkin(skin:Object):void

Sets the skin for the track of the toggle switch. The track forms the background of the toggle switch, and the thumb is the moveable foreground component.

Parameters

skin:Object — The skin to set.

See also

ToggleTrackSkin

Event Detail

select


Event Object Type: flash.events.Event
Event.type property = flash.events.Event.SELECT

Dispatches a select event when the selection of the control changes.

Examples

The following example creates a ToggleSwitch instance that traces out its state when it changes.

package
{
    import flash.display.Sprite;
    import flash.events.Event;
    
    import qnx.fuse.ui.buttons.LabelButton;
    import qnx.fuse.ui.buttons.ToggleSwitch;
    import qnx.fuse.ui.skins.buttons.RoundedButtonSkinBlack;
    import qnx.fuse.ui.skins.buttons.RoundedButtonSkinWhite;
    [SWF(height="600", width="1024", frameRate="30",backgroundColor="#FFFFFF")]
    public class toggleSample extends Sprite
    {
        private var myToggle:ToggleSwitch;
        private var myButton:LabelButton;
        public function toggleSample()
        {
            initializeUI();
        }
        
        private function initializeUI():void
        {    
            myToggle = new ToggleSwitch();
            myToggle.setPosition(200, 200);
            myToggle.selected = false;                      
            // listen to the select event the toggle switch dispatches
            myToggle.addEventListener(Event.SELECT, toggleChanged);
                
            this.addChild(myToggle);
        }
            
        private function toggleChanged( e:Event ):void
        {
            // if the toggle is selected, set the button skin to black, else white
            if ( myToggle.selected == true )
            {
                    trace("Toggle is ON");
            }
            else
            {
                    trace("Toggle is OFF");
            }
        }
    }
}
     




comments powered by Disqus