Get Layer By ComboBox

Discussion created by wangwei9969 on Jul 29, 2011
Latest reply on Jul 29, 2011 by DSwingley-esristaff
I want to be able to turn on and off the layer (visibleLayers) by ComboBox. I'm attempting to create three ComboBoxs for the user to toggle the visibility of layers in a dynamic map service layer. these three ComboxBoxs Respectively represent "dynamic services", "Year", "Month" .
I know the code is problem, but I will not modify,Please help me.
I referred to the

Here's One of them my relevant MapServer:

Service Description:

Map Name: Layers

All Layers and Tables


xianjie (0)
ma021011 (1)
ma021021 (2)
ma031101 (3)
ma061215 (4)
ma061215 (5)

eg."ma021011": "ma" representative "Lable"; "02" representative "Year(2002)"; "10" representative "month"; "11" representative "day"

my relevant mxml:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx=""
      minWidth="955" minHeight="600">
   import mx.collections.ArrayCollection;
   import mx.controls.RadioButton;
   private function loadLayerName():void
    //loop through each layer and add as a radiobutton
    var aa:String = "ma" + yearURL.selectedItem.toString() + monthURL.selectedItem.toString();
    for(var i:uint = 0; i < (dynamicLayer.layerInfos.length); i++)
     if (aa = dynamicLayer.layerInfos[i].name);
     var radioBtn:RadioButton = new RadioButton;
     radioBtn.groupName = "radioBtnGroup";
     radioBtn.value = i;
     radioBtn.label = dynamicLayer.layerInfos[i].name;
    //set the visible layer the first radio button
    radioBtnGroup.selectedValue = 0;
    dynamicLayer.visibleLayers = new ArrayCollection([0]);
   private function radioClickHandler(event:ItemClickEvent):void
    // update the visible layers to only show the layer selected
    dynamicLayer.visibleLayers = new ArrayCollection([event.index]);
  <!-- �?�?可�?�??素�?�?�?�?��?��?��?�对象�?�?��?�此�? -->

<esri:Map id="myMap">
  <esri:ArcGISDynamicMapServiceLayer id="dynamicLayer"
             url="{myURL.selectedItem}/MapServer" />

<mx:ComboBox id="myURL" selectedIndex="0" horizontalCenter="0">

<mx:ComboBox id="yearURL">

<mx:ComboBox id="monthURL">

<mx:Panel id="layerPanel" width="300" height="250" x="20" y="250" paddingLeft="20">
  <mx:RadioButtonGroup id="radioBtnGroup" itemClick="radioClickHandler(event)"/>