Flash CS3 Documentation |
|||
| Using ActionScript 2.0 Components > Collection Properties > 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;
// You must code a reference to the collection item class
// to force the compiler to include it as a dependency
// within the SWC
private var collItem:CompactDisc;
// You must code a reference to the mx.utils.CollectionImpl class
// to force the compiler to include it as a dependency
// within the SWC
private var coll:mx.utils.CollectionImpl;
// required methods for all classes
function init(Void):Void {
super.init();
}
function size(Void):Void {
super.size();
}
}
stop() function on Frame 1 in the Actions layer.You must include UIObject in the component's FLA file because, as you can see in the above class file, MyShelf extends UIObject.
This can be a simple rectangle; it's just a visual representation of the MyShelf component to use for learning purposes.
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.
|
NOTE |
|
You should have already created the CompactDisc class; otherwise, you'll get compiler errors when converting to a compiled clip. |
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00002529.html