Select to view content in your preferred language

Widget Communication Explained

4075
24
09-06-2011 11:45 AM
RobertScheitlin__GISP
MVP Emeritus
All,

  I have answered many threads where people are attempting to communicate between widget. So I thought that I would document in detail this previously undocumented portion of the Flex Viewer. In this PDF I explain what happens behind the scenes and provide code examples of what you need to add to your widgets. I also provide code for launching a widget from another widget so you can call a particular public function in the second widget. I hope this helps many.
Tags (2)
24 Replies
RobertScheitlin__GISP
MVP Emeritus
Bob,

   So what you are looking for is when widget A opens widget B closes?
0 Kudos
by Anonymous User
Not applicable
Exactly! And vice versa so that the two widgets remain mutual exclusive ...
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Bob,

   Here is some code that you could put in widget B to test if widget A is open and if it is close it:

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
by Anonymous User
Not applicable
Thanks Robert! That did the trick! Much appreciated!
0 Kudos
SeanHarkins
New Contributor III
Not sure if this thread is the appropriate spot for this question, but I figured I would try here so I might get Robert's assistance.  I have Widget A, which when its processing is complete opens Widget B.  Using the recommendations from Robert's great Widget Communication document I use the following code to accomplish this. From Widget A

var id_B:Number = ViewerContainer.getInstance().widgetManager.getWidgetId("B");
var baseWidget_B:IBaseWidget = ViewerContainer.getInstance().widgetManager.getWidget(id_B, true) as IBaseWidget;


This works correctly and Widget B opens.  However, with a new requirement, when Widget A has completed its processing I also need to open Widget C.  I use the following code

var id_B:Number = ViewerContainer.getInstance().widgetManager.getWidgetId("B");
var baseWidget_B:IBaseWidget = ViewerContainer.getInstance().widgetManager.getWidget(id_B, true) as IBaseWidget;
var id_C:Number = ViewerContainer.getInstance().widgetManager.getWidgetId("C");
var baseWidget_C:IBaseWidget = ViewerContainer.getInstance().widgetManager.getWidget(id_C, true) as IBaseWidget;


Now, Widget C opens correctly, but Widget B no longer does.  It seems that I can only dispatch a single WIDGET_RUN event from Widget A.  If I comment out the code for opening Widget C, Widget B opens correctly.  I'm fairly new at developing with the Viewer so any insight on this behavior would be greatly appreciated.
0 Kudos