AnsweredAssumed Answered

map.removeLayer(myLyr) does not work

Question asked by shaningesri on Oct 25, 2010
Latest reply on May 22, 2018 by fl.pires
Scenario description:
Created several checkboxes.  If a checkbox is checked, a layer is added, or else, the layer will be removed (see the code below).  However, I can't remove the added layer(s).  I run debugging, it does go through map.removeLayer(lyr), but the layer I created is still on the map.  If you have a better approach or find anything wrong in my code, please help.  Thanks.

private function ChkSettings (chk:ImageCheckBox, lyr:GraphicsLayer,
    ac:ArrayCollection, lyrName:String ):void {
   if (chk.selected == false) {
lyr.clear();
for (var i:Number = 0; i < map.layers.length; i++) {
  if (map.layers[i].name == lyrName) {
   map.removeLayer(lyr);
  }
}
   } else {
lyr = AddGeocodeLayer2(ac);
lyr.name = lyrName;
map.addLayer(lyr);
   }
}

Outcomes