Controlling widgets from HeaderControllerWidget

2251
3
Jump to solution
04-10-2013 09:33 AM
KennyWebster
New Contributor III
Hello,

I have a very customized HeaderControllerWidget to provide a very specific type of interface.  As part of this I have a few short cut links placed in the header itself that basically provide quick access/population to certain widgets.

My problem is that if the widget isn't already open, I don't seem to be able to get ahold of the correct event listener to wait for the widget to finish loading.  Code example:

widgetID = ViewerContainer.getInstance().widgetManager.getWidgetId("widgetName"); iWidget = ViewerContainer.getInstance().widgetManager.getWidget(widgetID,true);  if(!iWidget)  {   var timer:Timer = new Timer(1000,1);   timer.start();   timer.addEventListener(TimerEvent.TIMER_COMPLETE, completeHandler);   function completeHandler(event:TimerEvent):void   {    addSharedData("popUser", new ArrayCollection([userData.text]));    timer.stop();   }  }  else   addSharedData("popUser", new ArrayCollection([userData.text]));


So as you can see, as sort of a hack to get it working I have a timer delay inserted in the code if the widget is not already loaded.  The problem is that without the timer delay, if the widget is not already loaded, the getWidget returns null.  So I can't seem to get access to the widget object to add an event listener until it's loaded (at which point I no longer need an event listener).

The other option is I could have the widgets preload and just not have them visible.  However, again that feels kind of hacky.

Any other suggestions?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Kenny,

   You would be much better off having your widget call fetchSharedData(); in its init function and also add an event listener in your widgets init function for DATA_SENT after you addSharedData.

AppEvent.addListener(AppEvent.DATA_SENT, sharedDataUpdated2); fetchSharedData();


            private function sharedDataUpdated2(event:AppEvent):void             {                 var dataTable:Hashtable = event.data as Hashtable;                 if (dataTable.containsKey("popUser"))                 {                     var recAC:ArrayCollection = dataTable.find("popUser") as ArrayCollection;                     for (var i:Number = 0; i < recAC.length; i++)                     {                         var obj:Object = recAC;                         //todo                     }                     dataTable.remove("popUser");                 }else if(dataTable.containsKey("Deactivate_DrawTool"))                 {                     setMapAction(null, null, null, null);                 }             }

View solution in original post

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus
Kenny,

   You would be much better off having your widget call fetchSharedData(); in its init function and also add an event listener in your widgets init function for DATA_SENT after you addSharedData.

AppEvent.addListener(AppEvent.DATA_SENT, sharedDataUpdated2); fetchSharedData();


            private function sharedDataUpdated2(event:AppEvent):void             {                 var dataTable:Hashtable = event.data as Hashtable;                 if (dataTable.containsKey("popUser"))                 {                     var recAC:ArrayCollection = dataTable.find("popUser") as ArrayCollection;                     for (var i:Number = 0; i < recAC.length; i++)                     {                         var obj:Object = recAC;                         //todo                     }                     dataTable.remove("popUser");                 }else if(dataTable.containsKey("Deactivate_DrawTool"))                 {                     setMapAction(null, null, null, null);                 }             }
0 Kudos
KennyWebster
New Contributor III
ah ha!  I didn't know about the fetchSharedData function.  Thank you again Robert, that worked like a charm.  I feel like ESRI should be paying you by the volume of answers and support you provide to this community. 🙂
0 Kudos
RichardDiaz
New Contributor III
ah ha! I didn't know about the fetchSharedData function. Thank you again Robert, that worked like a charm. I feel like ESRI should be paying you by the volume of answers and support you provide to this community. 🙂


I second that!
0 Kudos