Select to view content in your preferred language

Close widget programatically

3431
10
03-09-2011 12:08 PM
SandraPanicucci
Deactivated User
I've set up my search widget to find a parameter from the URL and zoom to that feature. Once that goal has been accomplished I would like the widget to close automatically. Can it be done? Other option is changing all the pass parameters through URL into the mapManager and I;m trying not to go backwards from where I'm at.
Tags (2)
0 Kudos
10 Replies
ReneRubalcava
Esri Frequent Contributor
This thread covered how to close multiple widgets
http://forums.arcgis.com/threads/25015-Closing-Multiple-Widgets

But my post in there should work to close a single widget.
After that, it requires a little more work.
0 Kudos
SandraPanicucci
Deactivated User
Rene; Thanks for responding.

Where did you implement this code? Have made several attempts and not come up with the right answer. THough it looks like it shouldn't be as hard as I'm maknig it.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Sandra,

  If you are calling the code from within the widget than just use

        widgetState = WIDGET_CLOSED;
        notifyStateChanged(WidgetStates.WIDGET_CLOSED);
0 Kudos
SandraPanicucci
Deactivated User
When I add these lines  I get the error message in the attachment which generally seems to mean I need an import statement but don't seem to be able to figure out which one I need here. Any clue would be greatly appreciated.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Sandra,

   Are you not calling this code from inside a widget? If not than you need other code to get this to work.
0 Kudos
SandraPanicucci
Deactivated User
I'm attempting to call it from within the search widget.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Try this:

import com.esri.viewer.WidgetStates;

private function CloseMe():void
   {
    var data:Object =
    {
     id: this.widgetId,
     state: WidgetStates.WIDGET_CLOSED
    };
    ViewerContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_STATE_CHANGED,data,null));
   }
0 Kudos
SandraPanicucci
Deactivated User
1120: Access of undefined property widgetStates.


I'm using the 2.1 library if that makes a difference.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Sandra,

   Yep that makes a difference:

import com.esri.viewer.BaseWidget;

private function CloseMe():void
   {
    var data:Object =
    {
     id: this.widgetId,
     state: BaseWidget.WIDGET_CLOSED
    };
    ViewerContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_STATE_CHANGED,data,null));
   }
0 Kudos