User Guide
Simple collection example 189
5. Add the utilities classes to your FLA file by selecting Window > Common Libraries >
Classes and dragging UtilsClasses into the component’s library.
UtilsClasses contains the mx.utils.* package for the Collection interface.
6. Code a class that contains the collection item properties.
See “Defining the class for a collection item” on page 191.
Simple collection example
The following is a simple example of a component class file called MyShelf.as. This example
contains a collection property along with a minimal set of imports, methods, and declarations
for a component that inherits from the UIObject class.
If you import mx.utils.* in this example, the class names from mx.utils no longer need to be
fully qualified. For instance, mx.utils.Collection can be written as Collection.
import mx.utils.*;
// standard class declaration
class MyShelf extends mx.core.UIObject
{
// required variables for all classes
static var symbolName:String = "MyShelf";
static var symbolOwner:Object = Object(MyShelf);
var className:String = "MyShelf";
// the Collection metadata tag and attributes
[Collection(variable="myCompactDiscs",name="My Compact
Discs",collectionClass="mx.utils.CollectionImpl",
collectionItem="CompactDisc", identifier="Title")]
// get and set methods for the collection
public function get MyCompactDiscs():mx.utils.Collection
{
return myCompactDiscs;
}
public function set MyCompactDiscs(myCDs:mx.utils.Collection):Void
{
myCompactDiscs = myCDs;
}
// private class member
private var myCompactDiscs:mx.utils.Collection;
NOTE
Because UtilsClasses is associated with the FLA file, not the ActionScript class,
Flash throws compiler errors when you check syntax while viewing the component’s
ActionScript class.