Select to view content in your preferred language

Coercion Error with ESRI Flex Legend Component

2015
12
03-02-2011 08:11 AM
GregMcNeill
Emerging Contributor
Hi,
I am in the process of combing the ESRI Dynamic Map Layers on/off Flex Sample and ESRI Legend Component Flex Sample into one application; however, I am getting a #1034: Type Coercion error when I toggle a layer.  When it comes to Flex programming I am a real novice or more of a hack, my background is SQL and VB, so please bear with me.  My interpretation of the error is that I am somehow generating a type miss-match between the data structure used for the Layers list and the structure used for the Legend display.  I thought both of these structures used an array that was populated by Dynamic Service, myDynamicService, therefore, I am very confused as to what is going on here.  I have attached a copy of my source files but here is the code for the Default mxml:
<?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"
      xmlns:samples="com.*"
      pageTitle="Layers and Legends">

 <fx:Script>
  <![CDATA[
   import mx.events.FlexEvent;
   
   protected function application1_initializeHandler(event:FlexEvent):void
   {
    myLegend.layers = [ myDynamicService ];
   }
  ]]>
 </fx:Script>
 
 <s:layout>
  <s:VerticalLayout horizontalAlign="center"
        paddingBottom="20"
        paddingLeft="20"
        paddingRight="20"
        paddingTop="20"/>
 </s:layout>
 
 <mx:HDividedBox width="100%" height="100%">
  <esri:Map id="myMap">
   <esri:ArcGISDynamicMapServiceLayer id="myDynamicService" name=" "
              load="myDynamicService.defaultVisibleLayers()"
              url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/MapServer"/>
  </esri:Map>
  <mx:VBox width="40%" height="100%">
   <mx:Panel width="100%" height="50%" borderVisible="true" borderColor="#030303" title="Layers">
    <samples:LayerTOC mapLayer="{myDynamicService}"/>
   </mx:Panel>
   <mx:Panel width="100%" height="50%" borderVisible="true" borderColor="#030303" title="Legend">
    <esri:Legend id="myLegend"
      width="100%" height="100%"
      map="{myMap}"
      respectCurrentMapScale="true"/>
   </mx:Panel>
  </mx:VBox>
 </mx:HDividedBox>
</s:Application>
I hope someone can explain to me what is happening here to generate the Coercion error and hopefully help me resolve it so I can get the Legend to reflect what is displayed on the map.  Any help provided will be greatly appreciated, thank you.

- Greg
Tags (2)
0 Kudos
12 Replies
tanyabisen
Emerging Contributor
Hi Sarthak and Greg,

I downloaded the code which you shared,but I am having issues with the treeview control in TOC and dynamic legends turn on/off..I am new to Flex,if you could help me on this please.. i think there is some issue in the skins componenet.. I have included it outside the src folder but still no success
0 Kudos
GregMcNeill
Emerging Contributor
Hi Tanya,
  With the release of Flex API 2.3.1 you will not have to copy the LegendSkin.mxml from the API directory and modify the "visibleLayersChangeHandler()" that Sarthak had me do in my previous example.  Here is a updated version of that same application for use with the Flex API 2.3.1.  Hop[e this helps,

-Greg
0 Kudos
tanyabisen
Emerging Contributor
Thanks Greg, It worked perfectly the way I wanted... If you could help me with creating a treeview in TOC which will include the annotations.. any link or reference you have would be great..\


Thanks,
Tanya
0 Kudos