Accessing collection information programmatically
Flash provides programmatic access to collection data through the Collection and Iterator
interfaces. The Collection interface lets you add, modify, and remove items in a collection. The
Iterator interface allows you to loop through the items in a collection.
There are two scenarios in which to use the Collection and Iterator interfaces:
•
"Accessing collection information in a component class (AS) file" on page 963
•
"Accessing collection items at runtime in a Flash application" on page 964
Advanced developers can also create, populate, access, and delete collections programmatically;
for more information, see
Accessing collection information in a component class (AS) file
In a component's 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, use any of the following
approaches:
•
The Collection tag includes a
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 an iterator for the collection items by calling the
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
method returns type Object, so you must cast the result to 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 =
if (button.ButtonLink != undefined) {
item.data = button.ButtonLink;
}
else {
item.enabled = false;
}
"Collection interface (Flash Professional only)" on page
variable
button.ButtonLabel;
attribute, for which you specify a variable of type
Collection.getIterator()
Accessing collection information programmatically
169.
method,
Iterator.next()
963
Need help?
Do you have a question about the FLASH MX 2004-USING COMPONENTS and is the answer not in the manual?