Select to view content in your preferred language

1119: Access of possibly undefined property reference with static type Class

2607
6
07-28-2010 08:55 AM
GregMcNeill
Emerging Contributor
Hello, I am trying to modify the Dynamic_TOC.mxml example that came with the 1.3 API Library for Flex.  What I want to do is get the TOC to display in a popup window instead of in a box alongside the map as in the example. I have added another mxml component called Layers.mxmlfor the popup window but I am having an issue accessing the ArcGISDynamicMapServiceLayer on the Application mxml, I get the following error ???1119: Access of possibly undefined property myDynamicService through a reference with static type Class.???  My experience with Flex is very limited, I am learning as I am working through the issues, but I am guessing I have an issue with scope of the object and I don???t know how to instantiate globally.  Here is excerpts from my two mxml files with Map.mxml being the default application file:

Map.mxml

[INDENT]<esri:Map id="myMap">
[INDENT]<esri:ArcGISDynamicMapServiceLayer
[INDENT]id="myDynamicService"
url="http://localhost/ArcGIS/rest/services/myMap/MapServer"
load="myDynamicService.defaultVisibleLayers()"/>[/INDENT][/INDENT]
</esri:Map>[/INDENT]

[INDENT]//This works while it is on the same mxml
<layers:LayerTOC layer="{myDynamicService}" height="100%" width="230"/>[/INDENT]
Layers.mxml

<mx:TitleWindow
[INDENT][INDENT]xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:esri="http://www.esri.com/2008/ags"
xmlns:layers="layers.*"
title="Map Layers"
showCloseButton="true" 
verticalScrollPolicy="auto"
horizontalScrollPolicy="auto"
width="260" height="230"
close="{PopUpManager.removePopUp(this)}">[/INDENT]

[INDENT]<mx:Script>
[INDENT]<![CDATA[
[INDENT]import mx.managers.PopUpManager;[/INDENT]
]]>[/INDENT]
</mx:Script>

//This throws the error when it is on a different mxml
<layers:LayerTOC layer="{Map.myDynamicService}" height="100%" width="230"/>[/INDENT]
</mx:TitleWindow>[/INDENT]


Any help is greatly appreciated,

Thanks,

Greg
Tags (2)
0 Kudos
6 Replies
DrewDowling
Frequent Contributor
I haven't used the Dynamic_TOC.mxml but I think I would try adding a public property of type layers or dynamiclayer, or whatever is required, to the new layers.mxml. Something like

private var _layer:Layer;


            public function get layer():Layer
            {
                return _layer;
            }
           
            public function set layer(value:Layer):void
            {
                _layer = value;

            }

Then in your main mxml you can set this property once you have declared  the now component  Dynamic_TOC.mxml
0 Kudos
GregMcNeill
Emerging Contributor
Drew thank you, I appreciate your help.  I guess I am not understanding exactly what you are doing.  I tried adding your recommendation into my Layers.mmxl and received a ERROR 1046: Type was not found or was not a compile-time constant.  Then I thought that I needed to add the procedures you recommended to the Map.mxml where the service is originally called but that didn't work either.  I guess I am lost here until I see an example of an <esri:ArcGISDynamicMapServiceLayer /> being accessed from separate mxml.
0 Kudos
DasaPaddock
Esri Regular Contributor
Have you imported Layer?

e.g.

import com.esri.ags.layers.Layer;
0 Kudos
GregMcNeill
Emerging Contributor
Dasa, yes I did import Layer .

I have included a copy of my files so you can see exactly what I am attempting to do.  I apprecate everyone help, thanks.
0 Kudos
DasaPaddock
Esri Regular Contributor
Try changing Layers.mxml to this:

    <mx:Script>
        <![CDATA[
            [Bindable]
            public var layer:Layer;
         ]]>
    </mx:Script>

    <layers:LayerTOC layer="{layer}" height="100%" width="230"/>


and adding this to the LoadLayers():
lay.layer = myDynamicService;
0 Kudos
GregMcNeill
Emerging Contributor
Dasa,

    That did the trick!  Thank you, I really appreciated your help with this issue and I would not have made work without it.  I wondered if I needed to bind the service but I didn't have a clue how to go about it or if it was really what was needed.  It looks like I need to study up on how an when to use binding.  Again many thanks.

I have attached a copy of the working code with your recommendation in case anyone else needs help.

-Greg
0 Kudos