class ToggleSwitch
package feathers.controls
extends FeathersControl › MeasureSprite › ValidatingSprite
implements IFocusObject, IToggle
Similar to a light switch, with on and off states that may be toggled.
An alternative to a Check
, especially on mobile.
The following example creates a toggle switch, programmatically selects it, and listens for when the selection changes:
var toggleSwitch = new ToggleSwitch();
toggleSwitch.selected = true;
toggleSwitch.addEventListener(Event.CHANGE, (event) -> {
var toggleSwitch = cast(event.currentTarget, ToggleSwitch);
trace("toggle switch changed: " + toggleSwitch.selected);
});
this.addChild(toggleSwitch);
Events:
openfl.events.Event.CHANGE | Dispatched when |
---|
1.0.0
.See also:
Constructor
Variables
paddingLeft:Float
The minimum space, measured in pixels, between the toggle switch's left edge and the left edge of the thumb.
In the following example, the toggle switch's left padding is set to 20 pixels:
toggleSwitch.paddingLeft = 20.0;
1.0.0
.paddingRight:Float
The minimum space, measured in pixels, between the toggle switch's right edge and the right edge of the thumb.
In the following example, the toggle switch's right padding is set to 20 pixels:
toggleSwitch.paddingRight = 20.0;
1.0.0
.secondaryTrackSkin:DisplayObject
The skin to use for the toggle switch's optional secondary track. If a toggle switch has one track, it will fill the entire length of the toggle switch. If a toggle switch has a track and a secondary track, the primary track will stretch between the left edge of the toggle switch and the location of the slider's thumb, while the secondary track will stretch from the location of the toggle switch's thumb to the right edge of the toggle switch.
In the following example, a track skin and a secondary track skin are passed to the toggle switch:
var skin = new RectangleSkin();
skin.fill = SolidColor(0xaaaaaa);
toggleSwitch.trackSkin = skin;
var skin = new RectangleSkin();
skin.fill = SolidColor(0xcccccc);
toggleSwitch.secondaryTrackSkin = skin;
1.0.0
.See also:
selected:Bool
Indicates if the toggle switch is selected or not.
The following example selects the toggle switch:
toggleSwitch.selected = true;
Note: When changing the selected
property programatically, the
position of the thumb is not animated. To change the selection with
animation, call the setSelectionWithAnimation()
method.
1.0.0
.See also:
thumbSkin:DisplayObject
The skin to use for the toggle switch's thumb.
In the following example, a thumb skin is passed to the toggle switch:
var skin = new RectangleSkin();
skin.fill = SolidColor(0xcccccc);
toggleSwitch.thumbSkin = skin;
1.0.0
.See also:
toggleDuration:Float
The duration, measured in seconds, of the animation when the toggle switch is clicked or tap and the thumb slides to the other side.
In the following example, the duration of the animation that toggles the thumb is set to 500 milliseconds:
toggleSwitch.toggleDuration = 0.5;
1.0.0
.toggleEase:IEasing
The easing function used for the animation when the toggle switch is clicked or tap and the thumb slides to the other side.
In the following example, the ease of the animation that toggles the thumb is customized:
toggleSwitch.toggleEase = Elastic.easeOut;
1.0.0
.trackSkin:DisplayObject
The skin to use for the toggle switch's track.
In the following example, a track skin is passed to the toggle switch:
var skin = new RectangleSkin();
skin.fill = SolidColor(0xcccccc);
toggleSwitch.trackSkin = skin;
1.0.0
.See also:
Methods
setPadding(value:Float):Void
Sets all padding properties to the same value.
1.0.0
.See also: