User Guide
960 Appendix: Collection Properties
This appendix contains the following sections:
Defining a collection property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 960
Simple collection example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 960
Defining the class for a collection item. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 962
Accessing collection information programmatically . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 963
Exporting components that have collections to SWC files . . . . . . . . . . . . . . . . . . . . . . . . . . . 964
Using a component that has a collection property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 965
Defining a collection property
You define a collection property by using the Collection tag in a component’s ActionScript file.
For more information, see “About the Collection tag” on page 942.
Note: This section assumes that you know how to create components and inspectable component
properties.
To define a collection property:
1.
Create a FLA file for your component.
See “Creating a component movie clip” on page 927.
2.
Create an ActionScript class.
See “Creating the ActionScript class file” on page 930.
3.
In the ActionScript class, insert a Collection metadata tag.
For more information, see “About the Collection tag” on page 942.
4.
Define get and set methods for the collection in the component’s ActionScript file.
5.
Add the utilities classes to your FLA file by selecting Windows > Other Panels > Common
Libraries > Classes and dragging UtilsClasses into the component’s library.
UtilsClasses contains the mx.utils.* package for the Collection interface.
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.
6.
Code a class that contains the collection item properties.
See “Defining the class for a collection item” on page 962.
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 Collection.
import mx.utils.*;
// standard class declaration