User Guide

192 Collection Properties
Accessing collection information in a component
class (AS) file
In a components class file, you can write code that interacts with collection items defined
during authoring or at runtime.
To access collection item information in a component class file, you can use any of the
following approaches.
The Collection tag includes a variable attribute, for which you specify a variable of type
mx.utils.Collection. Use this variable to access the collection, as shown in this example:
[Collection(name="LinkButtons", variable="__linkButtons",
collectionClass="mx.utils.CollectionImpl", collectionItem="ButtonC",
identifier="ButtonLabel")]
public var __linkButtons:mx.utils.Collection;
Access the Iterator interface for the collection items by calling the
Collection.getIterator() method, as shown in this example:
var itr:mx.utils.Iterator = __linkButtons.getIterator();
Use the Iterator interface to step through the items in the collection. The
Iterator.next() method returns an Object, so you must define the type of your
collection item, as shown in this example:
while (itr.hasNext()) {
var button:ButtonC = ButtonC(itr.next());
...
}
Access collection item properties, as appropriate for your application, as shown in this
example:
item.label = button.ButtonLabel;
if (button.ButtonLink != undefined) {
item.data = button.ButtonLink;
}
else {
item.enabled = false;
}