Select to view content in your preferred language

Close one widget when another is opened

1758
4
Jump to solution
02-29-2012 05:22 AM
MartynSmith
New Contributor
My goal is to have "WidgetA" and "WidgetB" mutually exlusive (in fact really I only want to allow one widget open at a time). I found some code from RSchleitin's "widgets communications" thread that Robert posted to close one widget when another is opened:

for each (var widgetId:Number in ViewerContainer.getInstance().widgetManager.getAllLoadedWidgetIds()) {     if(ViewerContainer.getInstance().widgetManager.getWidget(widgetId).widgetTitle == "WidgetA")     AppEvent.dispatch(AppEvent.WIDGET_CLOSE, widgetId); }


Inserted above code into "WidgetB" it works great and closes "WidgetA" when "WidgetB" is opened.  I put the same code in  "WidgetA" (except exchanged for "WidgetB"). 

The problem is, if I open "WidgetB" ("WidgetA" closes), then open "WidgetA" again, both widgets remain open.  Any ideas on why this doesn't work both ways?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Martyn,

   Then go to the WidgetTemplate in the code ad add one:

<viewer:WidgetTemplate id="wTemplate"                            open="wTemplate_openHandler(event)"                            width="300" height="300"                            closed="AppEvent.dispatch(AppEvent.TOC_HIDDEN)"                            minimized="AppEvent.dispatch(AppEvent.TOC_HIDDEN)">


            import com.esri.viewer.ViewerContainer;             protected function wTemplate_openHandler(event:Event):void             {                 for each (var widgetId:Number in ViewerContainer.getInstance().widgetManager.getAllLoadedWidgetIds())                 {                     if(ViewerContainer.getInstance().widgetManager.getWidget(widgetId).widgetTitle == "WidgetA")                         AppEvent.dispatch(AppEvent.WIDGET_CLOSE, widgetId);                 }             }

View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus
Martyn,

   Are you putting that code in the init function or the widgetOpenedHandler? Because you should be adding it to the widgetOpenedHandler.
0 Kudos
MartynSmith
New Contributor
Robert- Thanks!

Hmm....I have it in the "init" function... There isn't a "widgetOpenedHandler" function (using the LayerList widget).
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Martyn,

   Then go to the WidgetTemplate in the code ad add one:

<viewer:WidgetTemplate id="wTemplate"                            open="wTemplate_openHandler(event)"                            width="300" height="300"                            closed="AppEvent.dispatch(AppEvent.TOC_HIDDEN)"                            minimized="AppEvent.dispatch(AppEvent.TOC_HIDDEN)">


            import com.esri.viewer.ViewerContainer;             protected function wTemplate_openHandler(event:Event):void             {                 for each (var widgetId:Number in ViewerContainer.getInstance().widgetManager.getAllLoadedWidgetIds())                 {                     if(ViewerContainer.getInstance().widgetManager.getWidget(widgetId).widgetTitle == "WidgetA")                         AppEvent.dispatch(AppEvent.WIDGET_CLOSE, widgetId);                 }             }
0 Kudos
MartynSmith
New Contributor
Wow, awesome Robert, that worked perfectly.  Thanks again for your help

Martyn
0 Kudos