Select to view content in your preferred language

PopupRenderSkin with radio buttons part 2

2998
12
Jump to solution
10-24-2012 05:00 PM
RhettZufelt
MVP Notable Contributor
I have taken the snippets from here:
http://forums.arcgis.com/threads/47909-PopUpRendererSkin.mxml-with-Radio-Buttons?p=243845&posted=1#p...

and am trying to get a radio button on the bottom of my popup window that turns on/off thier respective label service.
Everything seems to be working fine as far as the radio buttons, but the infoWinClose_Handler is giving me some issues.  It works just fine for the first item/layer clicked on, however, if I get popup info from a "different" layer, I get reference to null object error when I close any other popup window (other than the first one I click on).

Here is what I've gotten so far (well, at least the portions I've added)  I have tried several "if" statements to try to get it to only change visibility if it was one of the "toggle" layers, and ignore the "other" popups so I don't get the null issues, but have had no luck.

I need it to close the layer that was toggled on when the widget is closed.  Would really be nice if it would close the toggled on layer when "switching" to a different layer as well.  This would probalby solve the null issues.

The code that determines which layer to load, toggle on and off, and whether or not to include the toggle buttons is working fine, only the on close function that I'm having issues with.

Any ideas?

R_


 <fx:Script>   <![CDATA[     [Bindable] var RBlabel:String;            // variable used to capture the current (identified) layer name    [Bindable] var RBlayer:String;           //variable used to tell which layer to toggle on/off    [Bindable] var RBonsel:Boolean = false;  // variable used to capture "selected" state of the radio button    [Bindable] var RBoffsel:Boolean = true;  // variable used to capture "selected" state of the radio button     private function skin_preinitializeHandler(event:FlexEvent):void    {     // set the link styles //My Add                      off.visible = false;     on.visible = false;     RBlayer = "";     RBlabel = "";          if (hostComponent.featureLayer.url == "http://gis01.wch-rcc.com/ArcGIS/rest/services/Base/Buildings/MapServer/3"){      off.visible = true;      on.visible = true;          RBlayer = "Buildings";      RBlabel = "Building Labels";     }     if (hostComponent.featureLayer.url == "http://gis01.wch-rcc.com/ArcGIS/rest/services/Base/All_Waste_Sites/MapServer/1"){      off.visible = true;      on.visible = true;          RBlayer = "WasteSites";      RBlabel = "Point Labels";     }     if (hostComponent.featureLayer.url == "http://gis01.wch-rcc.com/ArcGIS/rest/services/Base/All_Waste_Sites/MapServer/2"){      off.visible = true;      on.visible = true;          RBlayer = "WasteSites";      RBlabel = "Line Labels";     }     if (hostComponent.featureLayer.url == "http://gis01.wch-rcc.com/ArcGIS/rest/services/Base/All_Waste_Sites/MapServer/3"){      off.visible = true;      on.visible = true;          RBlayer = "WasteSites";      RBlabel = "Poly Labels";     } //End My add     textLayoutConfiguration = new Configuration();     var textLayoutFormat:TextLayoutFormat = new TextLayoutFormat();     textLayoutFormat.color = getStyle("linkActiveColor")     textLayoutFormat.textDecoration = TextDecoration.UNDERLINE;     textLayoutConfiguration.defaultLinkActiveFormat = textLayoutFormat;      vGroup.addElement(ToggleLayers);   // My Add - this is not where I have it, just wanted to include it somewhere.   //My Add    protected function layerRBgroup_changeHandler(event:Event):void    {     var map:Map = hostComponent.map;     if (event.currentTarget.selectedValue == "on"){          map.getLayer(RBlabel).visible = true;       RBonsel = true;                                                 RBoffsel = false;      }     if (event.currentTarget.selectedValue == "off"){         map.getLayer(RBlabel).visible = false;         RBoffsel = true;                           RBonsel = false;           }    }    private function infoWinClose_Handler(event:Event):void    {            var map:Map = hostComponent.map;      map.getLayer(RBlabel).visible = false;      RBoffsel = true;      RBonsel = false;     }     }    //End My add   ]]>  </fx:Script>   <fx:Declarations>   <!--- @private -->   <s:RadioButtonGroup id="layerRBgroup" change="layerRBgroup_changeHandler(event)" />     <!--- @private -->   <s:HGroup gap="6" verticalAlign="middle" id="ToggleLayers">    <s:RadioButton id="on" value="on" group="{layerRBgroup}" label="Turn Labels On" selected="{RBonsel}" />    <s:RadioButton id="off" value="off" group="{layerRBgroup}" label="Turn Labels Off" selected="{RBoffsel}" />   </s:HGroup>  </fx:Declarations> </s:SparkSkin>
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Rhett,

   The skin_preinitializeHandler function only gets called at certain times in the code life cycle. If you want something to get evaluated every time something gets clicked than the place to put code is the commitProperties function.

View solution in original post

0 Kudos
12 Replies
RobertScheitlin__GISP
MVP Emeritus
Rhett,

   Where in your code are you even adding the close event? I don't see it any where in what you have posted.
0 Kudos
RhettZufelt
MVP Notable Contributor
Whoops, guess I trimmed it too much for posting.  I have it at the bottom of the skin_preinitialize right before the attachmentInspector function:

    attachmentInspector.addEventListener(AttachmentMouseEvent.ATTACHMENT_CLICK, attachmentInspector_attachmentClickHandler);
    hostComponent.parent.parent.parent.parent.addEventListener("close", infoWinClose_Handler);
   }
   
   private function attachmentInspector_attachmentClickHandler(event:AttachmentMouseEvent):void


I have noticed that it seems to keep a list of all the popup "layers" that I click, and then tries to close "each" of thier respective label feature classes with my closeHandler whenever I close one.

I.e., if I click on a building feature, then close the popup, it works fine, then click a Wastesite poly feature and close it, it works, but then I get an error as it tries to close the buildings lables.  If I then click on wastelines and close the popup, it works for wastelines, but then get an error as it tries to close the wastepoly lables, then another error as it tries to close the building labels.  If I click a wastepoint, it works, then just adds to the list it tries to close and errors on (as they are already closed), and so on.

R_
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Rhett,

   I don't really have the time to setup a test environment that replicates your senario buhere is what I am thinking the issue is:

            private function infoWinClose_Handler(event:Event):void
            {
                hostComponent.parent.parent.parent.parent.removeEventListener("close", infoWinClose_Handler)
                var map:Map = hostComponent.map;
                var lyr:Layer = map.getLayer(RBlabel);
                if(lyr){
                    lyr.visible = false;
                }
                RBoffsel = true;
                RBonsel = false;
            }
0 Kudos
RhettZufelt
MVP Notable Contributor
Thanks Robert, didn't think to "remove" the listener.  That get's rid of my null error issues, but once I close a popup from a particular layer, it won't initiate the infoWinClose_Handler again.  Odd as I can click and get popup for any of the four "configured" layers and it will run the close_handler on each of them the first time I click them.  If I click feature for a layer that has already had a popup open and then closed, it will not initiate the close function again.

Figure I need to re-initiate the listener, having issues trying to figure out where to put it without getting the null errors again.

Just figured out that if I put it at the bottom of the commitProperties function, it appears to be working as desired.

Thanks again for the help,

R_
0 Kudos
RhettZufelt
MVP Notable Contributor
Any idea why these changes break the eSearch widget popups?

I created a new OTB viewer with the eSearch widget.  enabled the PopupRenderSkin.mxml to customize.  no problems, works just fine.

However, If I add even this if statement:

            private function skin_preinitializeHandler(event:FlexEvent):void
            {
                // set the link styles
     if (hostComponent.featureLayer.url == "http://gis01.wch-rcc.com/ArcGIS/rest/services/Base/Buildings2/MapServer/0"){
   
     RBlayer = "Buildings";
     RBlabel = "Building Labels";
    }


and then click on one of the highlighted search results geometry (on the map, not the datagrid(s)) I get this error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
 at com.esri.ags.skins::PopUpRendererSkin/skin_preinitializeHandler()
 at com.esri.ags.skins::PopUpRendererSkin/___PopUpRendererSkin_SparkSkin1_preinitialize()
 at flash.events::EventDispatcher/dispatchEventFunction()
 at flash.events::EventDispatcher/dispatchEvent()
 at mx.core::UIComponent/dispatchEvent()
 at mx.core::UIComponent/initialize()
 at com.esri.ags.skins::PopUpRendererSkin/initialize()
 at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()
 at mx.core::UIComponent/addChild()
 at spark.components.supportClasses::SkinnableComponent/attachSkin()
 at spark.components.supportClasses::SkinnableComponent/validateSkinChange()
 at spark.components.supportClasses::SkinnableComponent/createChildren()
 at mx.core::UIComponent/initialize()
 at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()
 at mx.core::UIComponent/addChildAt()
 at spark.components::Group/addDisplayObjectToDisplayList()
 at spark.components::Group/http://www.adobe.com/2006/flex/mx/internal::elementAdded()
 at spark.components::Group/addElementAt()
 at spark.components::Group/addElement()
 at com.esri.ags.components::ContentNavigator/commitProperties()
 at mx.core::UIComponent/validateProperties()
 at mx.managers::LayoutManager/validateProperties()
 at mx.managers::LayoutManager/doPhasedInstantiation()
 at mx.managers::LayoutManager/doPhasedInstantiationCallback()


Seems odd that an "if" statement would give such an error as I expect it to just move past it since it should evaluate it to false.

I have tried to disable the popup from the eSearch, and it no longer shows if I click the data grid or results, However, If I click on one of the selected features, not only do I get the above error, I also get a popup with the config info from the esearch widget and not the regular popupconfig.xml.  It will show 1 of 2 and if I click the next arrow, it shows the regular popup window.

any ideas what could cause this?  If nothing else, is it possible to completly disable the eSearch popups (even though it looks like it is supposed to use it's own popuprenderskin)?

R_
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Rhett,

   It is simple the reason you are getting a null is that the hostComponent.featureLayer is null and this evaluate the url of the featurelayer if the featurelayer is null.
0 Kudos
RhettZufelt
MVP Notable Contributor
Rhett,

   It is simple the reason you are getting a null is that the hostComponent.featureLayer is null and this evaluate the url of the featurelayer if the featurelayer is null.


Figured it was something like that (assume you mean it "can't" evaluate the url), so thought I could evaluate if it is null, and if not, then evaluate my if statements something like such:

   private function skin_preinitializeHandler(event:FlexEvent):void
   {
    // set the link styles
         if (hostComponent.featureLayer.url != null){
             if (hostComponent.featureLayer.url == "http://gis01.wch-rcc.com/ArcGIS/rest/services/Base/Buildings2/MapServer/0"){
   
     RBlayer = "Buildings";
     RBlabel = "Building Labels";
    }
}



But I still get the null error.  Do I just have my syntax wrong or am I trying to do something that is not possible?

R_
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Rhett,

   That is because as I mentioned in my last post the hostComponent.featureLayer is null and you can not evealuate the url property of a null object.  So more like this:
if(hostComponent.featureLayer){
//do something
}
0 Kudos
RhettZufelt
MVP Notable Contributor
Thought I had tried that already and it didn't work.

I see now I had to strip off the .url.

Seems to be working now.

Thanks agian,

R_
0 Kudos