Interface for collections of hierarchical data, such as trees.

Events:

openfl.events.Event.CHANGE
feathers.events.HierarchicalCollectionEvent.ADD_ITEM
feathers.events.HierarchicalCollectionEvent.REMOVE_ITEM
feathers.events.HierarchicalCollectionEvent.REPLACE_ITEM
feathers.events.HierarchicalCollectionEvent.REMOVE_ALL
feathers.events.HierarchicalCollectionEvent.RESET
feathers.events.HierarchicalCollectionEvent.UPDATE_ITEM
feathers.events.HierarchicalCollectionEvent.UPDATE_ALL
feathers.events.HierarchicalCollectionEvent.FILTER_CHANGE
feathers.events.HierarchicalCollectionEvent.SORT_CHANGE
Available since

1.0.0

.

Variables

@:flash.propertyfilterFunction:T ‑> Bool

A function to determine if each item in the collection should be included or excluded from visibility through APIs like length and get().

The following example filters a collection of strings by searching for a substring at the beginning:

collection.filterFunction = (a:String) =>
{
	return StringTools.startsWith(a.toLowerCase(), "john");
};
Available since

1.0.0

.

See also:

@:flash.propertysortCompareFunction:(T, T) ‑> Int

A function to compare each item in the collection to determine the order when sorted.

The return value should be -1 if the first item should appear before the second item when the collection is sorted. The return value should be 1 if the first item should appear after the second item when the collection is sorted. Finally, the return value should be 0 if both items have the same sort order.

The following example sorts a collection of Float values:

collection.sortCompareFunction = (a:Float, b:Float) =>
{
	if (a > b) {
		return 1;
	} else if (a < b) {
		return -1;
	}
	return 0;
};
Available since

1.0.0

.

See also:

Methods

addAt(itemToAdd:T, location:Array<Int>):Void

Adds an item to the collection at the specified location, increasing the the length of the parent branch by one.

var location = [2, 0];
var item = { text: "New Item" };
collection.addAt(item, location);
Available since

1.0.0

.

See also:

contains(item:T):Bool

Determines if the collection contains the specified item.

The following example checks if a collection contains an item:

var item = { text: "New Item" };
collection.addAt(item, [0]);

var contained = collection.contains(item); // true
Available since

1.0.0

.

get(location:Array<Int>):T

Returns the item at the specified location within the collection.

The following example gets an item from a specific location:

var location = [2, 0];
var item = collection.get(location);

The following example iterates over the items at the root of a collection:

for(i in 0...collection.getLength()) {
	var location = [i];
	var item = collection.get(i);
}
Available since

1.0.0

.

getLength(?location:Array<Int>):Int

The number of items at the specified location within the collection. If called without a location, returns the length of the root.

The following example iterates over the items at the root of a collection:

for(i in 0...collection.getLength()) {
	var location = [i];
	var item = collection.get(location);
}
Available since

1.0.0

.

isBranch(item:T):Bool

Determines if an item from the collection is a branch or not.

The following example iterates over the items at the root of a collection and prints the locations of branches to the debug console:

for(i in 0...collection.getLength()) {
	var location = [i];
	var item = collection.get(location);
	if(collection.isBranch(item)) {
		trace("branch: " + location);
	}
}
Available since

1.0.0

.

locationOf(item:T):Array<Int>

Returns the location of the specified item, or null if the item is not in the collection.

The following example gets the location of an item in the collection:

var item = { text: "New Item" };
collection.addAt(item, [0]);

var index = collection.locationOf(item); // [0]
Available since

1.0.0

.

remove(item:T):Void

Removes an item from the collection.

var location = [2, 0];
var item = { text: "New Item" };
collection.addAt(item, location);
collection.remove(item);
Available since

1.0.0

.

See also:

removeAll():Void

Removes all items from the collection, decreasing the length of the root to zero.

The following example removes all items from a collection:

collection.removeAll();
Available since

1.0.0

.

See also:

removeAt(location:Array<Int>):T

Removes an item from the collection at the specified location, decreasing the length of the parent branch by one.

var location = [2, 0];
var item = { text: "New Item" };
collection.addAt(item, location);
collection.removeAt(location);
Available since

1.0.0

.

See also:

set(location:Array<Int>, value:T):Void

Replaces the item at the specified location in the collection with a new item.

The following example replaces an item in a collection:

var location = [2, 0];
collection.set(location, object);
Available since

1.0.0

.

See also:

updateAll():Void

Notifies components using the collection that all items should be considered changed.

The following example updates all items in the collection:

collection.updateAll();
Available since

1.0.0

.

See also:

updateAt(location:Array<Int>):Void

Notifies components using the collection that an item at the specified location has changed.

The following example updates an item in the collection:

var location = [2, 0];
collection.updateAt(location);
Available since

1.0.0

.

See also: