If a Flash application uses a component that has a collection property, you can access the collection property at runtime. This example adds several items to a collection property using the Values dialog box and displays them at runtime using the Collection and Iterator APIs.
To access collection items at runtime:
See Simple collection example.
This example builds on the MyShelf component and CompactDisc collection.
This example uses the instance name myShelf.
onClipEvent (mouseDown) {
import mx.utils.Collection;
import mx.utils.Iterator;
var myColl:mx.utils.Collection;
myColl = _parent.myShelf.MyCompactDiscs;
var itr:mx.utils.Iterator = myColl.getIterator();
while (itr.hasNext()) {
var cd:CompactDisc = CompactDisc(itr.next());
var title:String = cd.Title;
var artist:String = cd.Artist;
trace("Title: " + title + " Artist: " + artist);
}
}
To access a collection, use the syntax componentName.collectionVariable; to access an iterator and step through the collection items, use componentName.collectionVariable.getIterator().