Show NKSwitch

NKSwitch

Description

This control is used as a switch which has a boolean value.

Usage

init(x, y, callback)
initializes switch control with given coordinates and a callback (name of the function as string) to be called when switch value is changed. Callback format should be functionName(newValue, controlID). "newValue" can be either 1 or 0 and controlID is an ID of the control (in case you have one callback for many controls).

show()
shows initialized switch, does nothing if already shown.

hide()
hides initialized switch, does nothing if already hidden.

getState()
asynchronous method which returns the state of the switch (0 or 1).

setState(value)
sets the state of the switch with animation.

Example

Initialize the switch

var uiswitch = new NKSwitch();
uiswitch.init(20, 70, "switchChanged");
uiswitch.show();

See the example source code for a more detailed implementation.