Interface for collections of flat data, such as arrays or other lists.

Available since

1.0.0

.

Variables

@:flash.propertyread onlylength:Int

The number of items in the collection.

The following example iterates over the items in a collection:

for(i in 0...collection.length) {
	var item = collection.get(i);
}
Available since

1.0.0

.

@: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

add(item:T):Void

Inserts an item at the end of the collection, increasing the length by one.

The following example adds an item to a collection:

collection.add(object);
Available since

1.0.0

.

See also:

addAll(collection:IFlatCollection<T>):Void

Adds all items from one collection to another collection.

The following example adds a collection of items to another collection:

collection1.addAll(collection2);
Available since

1.0.0

.

addAllAt(collection:IFlatCollection<T>, index:Int):Void

Adds all items from one collection to another collection.

The following example adds a collection of items to another collection:

collection1.addAllAt(collection2, 0);
Available since

1.0.0

.

addAt(item:T, index:Int):Void

Inserts an item into the collection at the specified index, increasing the length by one.

The following example adds an item to the start of a collection:

collection.addAt(object, 0);
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(index:Int):T

Returns the item at the specified index in the collection.

The following example iterates over the items in a collection:

for(i in 0...collection.length) {
	var item = collection.get(i);
}
Available since

1.0.0

.

indexOf(item:T):Int

Returns the index of the specified item, or -1 if the item is not in the collection.

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

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

var index = collection.indexOf(item); // 0
Available since

1.0.0

.

iterator():Iterator<T>

Creates an iterator for the collection.

Available since

1.0.0

.

refresh():Void

Refreshes the collection using the filterFunction or sortCompareFunction without passing in a new values for these properties. Useful when either of these functions relies on external variables that have changed.

The following example refreshes the collection:

var includeAll = true;
collection.filterFunction = (item) =>
{
	if(includeAll)
	{
		return true;
	}
	return false;

};
includeAll = false;
collection.refresh();
Available since

1.0.0

.

remove(item:T):Void

Removes a specific item from the collection, decreasing the length by one, if the item is in the collection.

The following example removes an item from a collection:

var item = { text: "New Item" };
collection.add(item);
collection.remove(item);
Available since

1.0.0

.

See also:

removeAll():Void

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

The following example removes all items from a collection:

collection.removeAll();
Available since

1.0.0

.

See also:

removeAt(index:Int):T

Removes an item from the collection at the specified index, decreasing the length by one.

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

1.0.0

.

See also:

@:value({ collection : null })reset(?collection:IFlatCollection<T>):Void

Removes all items from a collection and replaces it with the items from another collection.

The following example resets a collection:

collection1.reset(collection2);
Available since

1.0.0

.

See also:

set(index:Int, item:T):Void

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

The following example replaces an item in a collection:

collection.set(0, 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(index:Int):Void

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

The following example updates an item in the collection:

collection.updateAt(0);
Available since

1.0.0

.

See also: