User Guide
Accessing collection information programmatically 191
This allows you to drag the MyShelf SWF file (the compiled clip that’s added to the
library) into the MyShelf.fla file to test the component. Whenever you recompile the
component, a Resolve Library Conflict dialog box appears, because an older version of the
component already exists in the library. Choose to replace existing items.
Defining the class for a collection item
You code the properties for a collection item in a separate ActionScript class, which you define
as follows:
■ Define the class such that it does not extend UIObject or UIComponent.
■ Define all properties using the Inspectable tag.
■ Define all properties as variables. Do not use get and set (getter/setter) methods.
The following is a simple example of a collection item class file called CompactDisc.as.
class CompactDisc{
[Inspectable(type="String", defaultValue="Title")]
var title:String;
[Inspectable(type="String", defaultValue="Artist")]
var artist:String;
}
To view the CompactDisc.as class file, see “Simple collection example” on page 189.
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 192
■ “Accessing collection items at runtime in a Flash application” on page 193
Advanced developers can also create, populate, access, and delete collections
programmatically; for more information, see “Collection interface (Flash Professional only)”
in the Components Language Reference.
NOTE
You should have already created the CompactDisc class; otherwise, you’ll get
compiler errors when converting to a compiled clip.