Hello,
Thanks Robert for your help. It works now perfectly now. I've followed your method:
I've create a function that loop into the map to get the layer names and store them in an array, then function "toc.excludeLayers" exclude them all from the TOC.
private function getLayers():Array{
var counter:int ;
var thisLayer:Layer;
var layerArray:Array = new Array();
layerArray = _map.layerIds;
toc.excludeLayers=layerArray;
for( counter=1;counter<=layerArray.length;counter++)
{
var layerName:String = layerArray[counter];
}
return layerArray;
}
Then I've created one button for each "layer" (map-service) which contains the layer label (the buttons are in a (ButtonBar). By clicking on the buttons, the label is sent into this function :
public function ClickHandler(event:ItemClickEvent):void{
toc.includeLayers = (event.label);
toc.hideTopLevelItems = true;
tocPanel.title = (event.label); }
The first action include the layer (in the TOC)
The second hide the top level (the tree root) and drop the sublevel down at the same time !!
Finaly, the last one past the selected name in the Panel Title...
Done !
The only thing I'm not quite sure about is that I needed to "connect" the map with my application to be able to use some methods in the loop function ("_map.layerIds"). I've made it working by coping some piece of code I found on the forum and on the TOC.As but I don't quite understand:
private var _map:Map;
private var _mapChanged:Boolean = false;
private function Init():void {
SiteContainer.addEventListener(AppEvent.MAP_LOADED, initMap);
}
private function initMap(event:AppEvent):void {
_map = event.data as Map;
}
It works perfectly, but now I've got a new question, I'll write a new thread...
Cheers,