Collection class

ActionScript Class Name mx.utils.Collection

The collection interface lets you programmatically manage a group of related items, called collection items. Each collection item in this set has properties that are described in the metadata of the collection item class definition.

NOTE

The Collection class is supported only if you are working in a document that specifies ActionScript 2.0 in its Publish Settings.

Components can expose properties as collections, which you can manipulate while authoring by using the Values dialog box from the Component inspector. Using this dialog box, you can add items, remove items, change properties of items, and change the position of items within the collection. For more information on collections and collection items, see About the Collection tag in Using ActionScript 2.0 Components.

You typically use the collection interface with components that use the Collection metadata tag to create collection properties. Although you can create, access, and delete Collection instances programmatically, collections are most often used in the context of a component. Flash provides implementations of both collection-related interfaces (CollectionImpl for Collection, and IteratorImpl for Iterator).

Method summary for the Collection interface

The following table lists the methods of the Collection interface.

Method

Description

Collection.addItem()

Adds a new item to the end of the collection.

Collection.contains()

Indicates whether the collection contains the specified item.

Collection.clear()

Removes all elements from the collection.

Collection.getItemAt()

Returns an item within the collection by using its index.

Collection.getIterator()

Returns an iterator over the elements in the collection.

Collection.getLength()

Returns the number of items in the collection.

Collection.isEmpty()

Indicates whether the collection is empty.

Collection.removeItem()

Removes the specified item from the collection.