qnx.ui.buttons.ToggleSwitch

ToggleSwitch

Properties | Methods | Events | Examples


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

The ToggleSwitch represents a button that has one of two states indicating an "ON" or "OFF" state.

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:
PlayBook Tablet OS Version:   1.0.6

View the examples

See also

Button (toggle property)



Public Properties

 PropertyDefined By
 Inheritedactive : Boolean
Gets or sets the active property of the Slider.
Slider
 Inheritedcontainment : String
Gets or sets a property that determines how a component is contained within a parent container.
UIComponent
  defaultLabel : String
Gets or sets the String text for the default, or OFF, label.
ToggleSwitch
  embedFonts : Boolean
Gets or sets the embedFonts property of the internal TextField of the ToggleSwitch.
ToggleSwitch
 Inheritedmaximum : Number
Gets or sets the maximum value of the slider.
Slider
 Inheritedminimum : Number
Gets or sets the minimum value of the slider.
Slider
  selected : Boolean
Gets or sets the value of the switch (the position of the thumb).
ToggleSwitch
  selectedLabel : String
Gets or sets the String text for the selected, or ON, label.
ToggleSwitch
 Inheritedsize : Number
Gets or sets the size for this component (as a percentage of the container's size, or in pixels).
UIComponent
 InheritedsizeMode : String
Gets or sets the size mode for this component.
UIComponent
 InheritedsizeUnit : String
Gets or sets the unit of measure for the size property.
UIComponent
 Inheritedvalue : Number
Gets or sets the current value of the slider.
Slider

Public Methods

 MethodDefined By
  
Creates a ToggleSwitch instance.
ToggleSwitch
 Inherited
destroy():void
Call this method when you want to have your object collected by the garbage collector.
UIComponent
 Inherited
drawNow():void
Calls the draw() method.
UIComponent
  
getTextFormatForState(state:String):TextFormat
Returns the TextFormat object for a specified state.
ToggleSwitch
 Inherited
invalidate(property:String = all, 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
 Inherited
setFillSkin(skin:Object):void
Sets the fill skin for the slider.
Slider
 Inherited
setPosition(x:Number, y:Number):void
Sets the x and y position of the component.
UIComponent
 Inherited
setSize(w:Number, h:Number):void
Sets the width and height of the component.
UIComponent
  
setTextFormatForState(format:TextFormat, state:String):void
Sets the TextFormat object for the label for a given state.
ToggleSwitch
 Inherited
setThumbSkin(skin:Object):void
Sets the skin for the slider thumb button.
Slider
 Inherited
setTrackSkin(skin:Object):void
Sets the skin for the track of the slider.
Slider

Protected Methods

 MethodDefined By
 Inherited
callLater(method:Function):void
Calls the specified method on the next frame or the next render, which ever happens first.
UIComponent
 Inherited
createInstance(linkage:Object):DisplayObject
Calling this method will attempt to create a DisplayObject instance based on the value of the linkage parameter.
UIComponent
 Inherited
draw():void
Called every time you set the width and height of the component.
UIComponent
 Inherited
isInvalid(property:String, ... properties):Boolean
Checks to see if the property is invalid and returns true if it is.
UIComponent
 Inherited
onAdded():void
Called when the instance is added to the stage.
UIComponent
 Inherited
onRemoved():void
Called when the instance is removed from the stage.
UIComponent
 Inherited
setEnabled(val:Boolean):void
Called when the enabled property changes.
UIComponent
 Inherited
validate(property:String = all):void
Lets the component know that the specified property has been validated.
UIComponent

Events

 Event Summary Defined By
  Dispatches a select event when the selection of the control changes.ToggleSwitch
 Inherited Dispatched when a drag event ends.Slider
 Inherited Dispatched when a drag event starts.Slider
 Inherited Dispatched when the slider is moved by the user.Slider

Property Detail

defaultLabel


defaultLabel:String

Gets or sets the String text for the default, or OFF, label.

By definition, a toggle switch has two states. By default, the ToggleSwitch states are set to "Off" and "ON", however you can define your own states by setting the defaultLabel and selectedLabel properties.

The default value is "OFF".


Implementation

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

See also

selectedLabel

embedFonts


embedFonts:Boolean

Gets or sets the embedFonts property of the internal TextField of the ToggleSwitch.

When set to false, fonts are rendered as device fonts. When set to true, you must specify a font using the font property of a TextFormat object and set it using the setTextFormatForState() method.

This font must be included in your application. If it is not included, the text will not be rendererd.

The default value is false.


Implementation

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

See also

setTextFormatForState()

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 String text for the selected, or ON, label.

By definition, a toggle switch has two states. By default, the ToggleSwitch states are set to "Off" and "ON", however you can define your own states by setting the defaultLabel and selectedLabel properties.


Implementation

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

See also

defaultLabel

Constructor Detail

ToggleSwitch()


public function ToggleSwitch()

Creates 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.

Returns

TextFormat — The TextFormat object for the specified state.

See also

setTextFormatForState()
SkinStates

setTextFormatForState()


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

Sets the TextFormat object for the label for a given state.

Valid state parameter values are:

  • selected
  • default

In the following example, the a TextFormat object is applied to the selected state label:

         var myFormat:TextFormat = new TextFormat();
         myFormat.font = "BBAlpha Sans";
         myFormat.size = 22;
         myFormat.color = 0xFFFFFF;            
         
         myToggle = new ToggleSwitch();
         myToggle.setPosition(200, 200);
         myToggle.defaultLabel = "Light";
         myToggle.selectedLabel = "Dark";
         myToggle.selected = false;
         myToggle.setTextFormatForState(myFormat, "selected");
         

Parameters

format:TextFormat — The TextFormat object to apply to the label.
state:String — The state for which to apply the TextFormat object.

See also

SkinStates
getTextFormatForState()

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 you can use to change the skin of a LabelButton.

package
{
    import flash.display.Sprite;
    import flash.events.Event;
    
    import qnx.ui.buttons.LabelButton;
    import qnx.ui.buttons.ToggleSwitch;
    import qnx.ui.skins.buttons.RoundedButtonSkinBlack;
    import qnx.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.defaultLabel = "Light";
            myToggle.selectedLabel = "Dark";
            myToggle.selected = false;            
            // listen to the select event the toggle switch dispatches
            myToggle.addEventListener(Event.SELECT, themeChange);
            
            this.addChild(myToggle);
            
            myButton = new LabelButton();
            myButton.label = "myButton";
            myButton.setPosition(200, 150);
            
            this.addChild(myButton);
        }
        
        private function themeChange( e:Event ):void
        {
            // if the toggle is selected, set the button skin to black, else white
            if ( myToggle.selected == true )
            {
                myButton.setSkin(RoundedButtonSkinBlack);
                    
            }
            else
            {
                myButton.setSkin(RoundedButtonSkinWhite);
            }
        }
        
    }
}