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

Events:

openfl.events.Event.CHANGE

Dispatched when ToggleGroup.selectedItem or ToggleGroup.selectedIndex changes.

Available since

1.0.0

.

See also:

Constructor

new()

Creates a new ToggleGroup object.

Available since

1.0.0

.

Variables

read onlynumItems:Int

The number of items added to the group.

Available since

1.0.0

.

requireSelection:Bool

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 requireSelection is set to true, 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.requireSelection = false;
Available since

1.0.0

.

@:bindable("change")selectedIndex:Int

The index of the currently selected toggle.

When the value of the selectedIndex property changes, the component will dispatch an event of type Event.CHANGE.

In the following example, the selected index is changed:

group.selectedIndex = 2;
Available since

1.0.0

.

See also:

@:bindable("change")selectedItem:IToggle

The currently selected toggle.

When the value of the selectedItem property changes, the component will dispatch an event of type Event.CHANGE.

In the following example, the selected item is changed:

group.selectedItem = radio;
Available since

1.0.0

.

See also:

Methods

addItem(item:IToggle):Void

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

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

group.addItem(radio);
Available since

1.0.0

.

See also:

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);
Available since

1.0.0

.

See also:

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);
Available since

1.0.0

.

hasItem(item:IToggle):Bool

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
}
Available since

1.0.0

.

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();
Available since

1.0.0

.

removeItem(item:IToggle):Void

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

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

group.removeItem(radio);
Available since

1.0.0

.

See also:

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);
Available since

1.0.0

.