Hi steve.What is the base idea? Why do you need to keep graphics layers in separate container?Even if it would have been possible to hold the layers in "UIComponent" it would not give you anything.UIComponentThe UIComponent class is the base class for all visual components, both interactive and noninteractive.
The UIComponent class is not used as an MXML tag, but is used as a base class for other classes.
But if there is a need in the container, why not take "ArrayCollection"?private var myGraphicsLayersCollection:ArrayCollection = new ArrayCollection();
private function addGraphicsLayerToCollection():void {
var grLayer:GraphicsLayer = new GraphicsLayer();
grLayer.id = "grLayer1";
grLayer.name = "First Gr Layer";
myGraphicsLayersCollection.addItem(grLayer);
}
private function getGraphicsLayerFromCollectionById(layerId:String):GraphicsLayer {
for each (var layer:GraphicsLayer in myGraphicsLayersCollection) {
if (layerId == layer.id) {
return layer;
}
}
return null;
}
private function removeGraphicsLayerFromCollectionById(layerId:String):Boolean {
var isRemoved:Boolean = false;
for each (var layer:GraphicsLayer in myGraphicsLayersCollection) {
if (layerId == layer.id) {
var index:int = layerList.getItemIndex(layer);
layerList.removeItemAt(index);
isRemoved = true;
break;
}
}
return isRemoved;
}
private function collectionToMap():void {
for each (var layer:GraphicsLayer in myGraphicsLayersCollection) {
// each layer extends UIComponent, so its ID is unique
var existingLayer:Layer = mapMap.getLayer(layer.id);
if (!existingLayer)
mapMap.addLayer(layer);
}
}
Sample - [ATTACH=CONFIG]22038[/ATTACH]