Packagefeathers.core
Classpublic class ToggleGroup
InheritanceToggleGroup Inheritance starling.events.EventDispatcher

Product Version : Feathers 1.0.0

Controls the selection of two or more IToggle instances where only one may be selected at a time.

See also

IToggle


Public Properties
 PropertyDefined By
  isSelectionRequired : Boolean
Determines if the user can deselect the currently selected item or not.
ToggleGroup
  numItems : int
[read-only] The number of items added to the group.
ToggleGroup
  selectedIndex : int
The index of the currently selected toggle.
ToggleGroup
  selectedItem : IToggle
The currently selected toggle.
ToggleGroup
Public Methods
 MethodDefined By
  
Constructor.
ToggleGroup
  
addItem(item:IToggle):void
Adds a toggle to the group.
ToggleGroup
  
getItemAt(index:int):IToggle
Returns the item at the specified index.
ToggleGroup
  
Returns the index of the specified item.
ToggleGroup
  
hasItem(item:IToggle):Boolean
Determines if the group includes the specified item.
ToggleGroup
  
Removes all toggles from the group.
ToggleGroup
  
removeItem(item:IToggle):void
Removes a toggle from the group.
ToggleGroup
  
setItemIndex(item:IToggle, index:int):void
Changes the index of a specified item.
ToggleGroup
Events
 Event Summary Defined By
  Dispatched when the selection changes.ToggleGroup
Property Detail
isSelectionRequiredproperty
isSelectionRequired:Boolean

Determines if the user can deselect the currently selected item or not. The selection may always be cleared programmatically by setting the selected index to -1 or the selected item to null.

If isSelectionRequired is set to true and the toggle group has items that were added previously, and there is no currently selected item, the item at index 0 will be selected automatically.

In the following example, selection is not required:

group.isSelectionRequired = false;

The default value is true.


Implementation
    public function get isSelectionRequired():Boolean
    public function set isSelectionRequired(value:Boolean):void
numItemsproperty 
numItems:int  [read-only]

The number of items added to the group.


Implementation
    public function get numItems():int
selectedIndexproperty 
selectedIndex:int

The index of the currently selected toggle.

In the following example, the selected index is changed:

group.selectedIndex = 2;

The default value is -1.


Implementation
    public function get selectedIndex():int
    public function set selectedIndex(value:int):void
selectedItemproperty 
selectedItem:IToggle

The currently selected toggle.

In the following example, the selected item is changed:

group.selectedItem = radio;

The default value is null.


Implementation
    public function get selectedItem():IToggle
    public function set selectedItem(value:IToggle):void
Constructor Detail
ToggleGroup()Constructor
public function ToggleGroup()

Constructor.

Method Detail
addItem()method
public function addItem(item:IToggle):void

Adds a toggle to the group. If it is the first item added to the group, and isSelectionRequired is true, it will be selected automatically.

In the following example, an item is added to the toggle group:

group.addItem( radio );

Parameters

item:IToggle

getItemAt()method 
public function getItemAt(index:int):IToggle

Returns the item at the specified index. If the index is out of range, a RangeError will be thrown.

In the following example, an item's at a specific index is returned:

var item:IToggle = group.getItemAt( 2 );

Parameters

index:int

Returns
IToggle

See also

getItemIndex()method 
public function getItemIndex(item:IToggle):int

Returns the index of the specified item. Result will be -1 if the item has not been added to the group.

In the following example, an item's index is calculated:

var index:int = group.getItemIndex( radio );

Parameters

item:IToggle

Returns
int
hasItem()method 
public function hasItem(item:IToggle):Boolean

Determines if the group includes the specified item.

In the following example, we check if an item is in the toggle group:

if( group.hasItem( radio ) )
{
    // do something
}

Parameters

item:IToggle

Returns
Boolean
removeAllItems()method 
public function removeAllItems():void

Removes all toggles from the group. No item will be selected.

In the following example, all items are removed from the toggle group:

group.removeAllItems();

removeItem()method 
public function removeItem(item:IToggle):void

Removes a toggle from the group. If the item being removed is selected and isSelectionRequired is true, the final item will be selected. If isSelectionRequired is false instead, no item will be selected.

In the following example, an item is removed from the toggle group:

group.removeItem( radio );

Parameters

item:IToggle

setItemIndex()method 
public function setItemIndex(item:IToggle, index:int):void

Changes the index of a specified item. Throws an ArgumentError if the specified item hasn't already been added to this group.

In the following example, an item's index is changed:

group.setItemIndex( radio, 2 );

Parameters

item:IToggle
 
index:int

Event Detail
change Event
Event Object Type: starling.events.Event
Event.type property = starling.events.Event.CHANGE

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.