To show all visible by default layers:dynamicLayer.visibleLayers = null;
To hide all layers set empty collection:dynamicLayer.visibleLayers = new ArrayCollection();
To show all layers:dynamicLayer.visibleLayers = new ArrayCollection([array of all layers id's]);;
example:<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:esri="http://www.esri.com/2008/ags">
<s:layout>
<s:HorizontalLayout paddingBottom="10"
paddingLeft="10"
paddingRight="10"
paddingTop="10"/>
</s:layout>
<fx:Script>
<![CDATA[
import com.esri.ags.events.LayerEvent;
import com.esri.ags.layers.supportClasses.LayerInfo;
import mx.collections.ArrayCollection;
[Bindable]
private var layersList:ArrayCollection = null;
[Bindable]
private var visibleLayers:ArrayCollection = null;
protected function onShowAllClick(event:MouseEvent):void
{
visibleLayers = null;
dlayer.refresh();
}
protected function onHideAllClick(event:MouseEvent):void
{
visibleLayers = new ArrayCollection();
dlayer.refresh();
}
protected function onShowSelectedClick(event:MouseEvent):void
{
var selectedLayer:LayerInfo = ddlLayers.selectedItem as LayerInfo;
visibleLayers = new ArrayCollection([selectedLayer.layerId]);
dlayer.refresh();
}
protected function onLayerLoad(event:LayerEvent):void
{
layersList = new ArrayCollection(dlayer.layerInfos);
ddlLayers.selectedIndex = 0;
}
]]>
</fx:Script>
<s:Panel width="100%"
height="100%"
title="Map">
<esri:Map id="map">
<esri:extent>
<esri:Extent id="lowerManhattan"
xmin="-8239000" ymin="4968000" xmax="-8235000" ymax="4971000">
<esri:SpatialReference wkid="102100"/>
</esri:Extent>
</esri:extent>
<esri:ArcGISTiledMapServiceLayer name="Base layer - tiled"
url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
<esri:ArcGISDynamicMapServiceLayer id="dlayer"
name="Demographics layer - dynamic"
visibleLayers="{visibleLayers}"
load="onLayerLoad(event)"
url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer" />
</esri:Map>
</s:Panel>
<s:Panel width="300"
height="100%"
title="Filters">
<s:VGroup paddingBottom="5"
paddingLeft="5"
paddingRight="5"
paddingTop="5"
gap="10">
<s:Button id="btnShowAll"
label="Show all layers"
click="onShowAllClick(event)"/>
<s:DropDownList id="ddlLayers"
width="100%"
dataProvider="{layersList}"
labelField="name" />
<s:Button id="btnShowSelected"
label="Show selected layer"
click="onShowSelectedClick(event)"/>
<s:Button id="btnHideAll"
label="Hide all layers"
click="onHideAllClick(event)"/>
</s:VGroup>
</s:Panel>
</s:Application>