While creating FLA Based Component we need to display the properties of Component to flash parameters panel available for user to edit. The property values can be edited by the user in the Values dialog box (opened from a text box within the Parameters tab for your component). these are called Collection Properties.
To add a collection properties to your component. We can define it directly to a variable or can define through getter setter method.
I will be discussing here for defining the collection properties to a variable.
1. Define two classes and that need not to extend or implement any classes. Name those classes as for your need I am naming as Collection.as and CollectionItem.as.
2. Collection class looks like :-
package{
public class Collection
{
private var _items:Array;
public function Collection(){
super();
_items = new Array();
}
public function addItem(item:Object):Boolean {
if (item != null) {
_items.push(item);
return true;
}
return false;
}
public function clear():void {
_items = new Array();
}
public function getItemAt(index:Number):Object {
return(_items[index]);
}
}
}
Nothing more you need here it define s an array and when user add any item from parameter then it will be pushed into this array(that we dont have to think how does it do..). Method getItemAt gets the data from the array and returns as object.
3. Now Comes CollectionItem Class
Basically it define the items of the Collection. The list of inspectable parameters for this class determines the list of properties shown in the Values dialog box for each item.
package {
public class FrustumCollectionItem
{
[Inspectable (defaultValue="")]
public var label:String;
[Inspectable (defaultValue="")]
public var data:String;
[Inspectable (defaultValue="")]
public var color:String;
public function FrustumCollectionItem() {
label = “”;
data = “”;
color = “”;
}
}
}
After you completed making these two classes not come to the original class where you need to make a variable as collection properties.
4. Defien the variable as object. as
public var dataSource:Object; Now you need to import the above to classes (Collection.as and CollectionItem.as)
5. Now the last step to go……..where you declared the variable dataSource add a line just above that as :-
[Collection(collectionClass="Collection", collectionItem="CollectionItem", identifier="label")]
public var dataSource:Object;
you are done now……..njoy