Select to view content in your preferred language

sharedData widget

907
5
07-25-2010 09:09 AM
FaisalBukhari
Deactivated User
Dear Robert

i use same below code but its not working  i am using flex viewer 1.3

any idea


Regards
Faisal

//In widget A
var recAC:ArrayCollection = new ArrayCollection();
recAC.addItem(someItem);
addSharedData("Some Unique Name", recAC);

//In widget B
private function init():void
{
    if (configXML)
    ...
    SiteContainer.addEventListener(AppEvent.DATA_UPDATED, sharedDataUpdated);
}

private function sharedDataUpdated(event:AppEvent):void
{
var dataTable:Hashtable = event.data as Hashtable;
if (dataTable.containsKey("Some Unique Name"))
{
  var recAC:ArrayCollection = dataTable.find("Some Unique Name") as ArrayCollection;
  var obj:someItem = recAC[0];
  //do something with obj
  dataTable.remove("Some Unique Name");
}
}
Tags (2)
0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus
Faisal,

  I don't see anything wrong with your code except that I would call
SiteContainer.addEventListener(AppEvent.DATA_UPDAT ED, sharedDataUpdated);

outside of the if configXML actually before the if configXML.
0 Kudos
NadirHussain
Frequent Contributor
Dear Robert
i am using same code which faisal write down.i am facing same problem.i tried your solutin.i call share data statment before Config XML.but it is not working.pls help.

Thanks in advance
Nadir
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Guys,
   I am not sure what you are doing wrong. I developed two very simple widgets in SFV1.3 to show how it works and to test the messaging between widgets any they work just fine.

Widget A:
<?xml version="1.0" encoding="utf-8"?>
<BaseWidget xmlns="com.esri.solutions.flexviewer.*" xmlns:mx="http://www.adobe.com/2006/mxml">
 <mx:Script>
  <![CDATA[
   import mx.collections.ArrayCollection;
   
   private function sendMessage():void
   {
    var recAC:ArrayCollection = new ArrayCollection();
    recAC.addItem("Hello World");
    addSharedData("Some Unique Name", recAC);
   }
  ]]>
 </mx:Script>
 <WidgetTemplate id="wTemplate">
  <mx:Button x="10" y="10" label="Button" click="sendMessage()"/>
 </WidgetTemplate>
</BaseWidget>


Widget B:
<?xml version="1.0" encoding="utf-8"?>
<BaseWidget xmlns="com.esri.solutions.flexviewer.*" xmlns:mx="http://www.adobe.com/2006/mxml"
  creationComplete="init()">
 <mx:Script>
  <![CDATA[
   import com.esri.solutions.flexviewer.SiteContainer;
   import com.esri.solutions.flexviewer.utils.Hashtable;
   import mx.collections.ArrayCollection;
   import com.esri.solutions.flexviewer.AppEvent;
   
   private function init():void
   {
    SiteContainer.addEventListener(AppEvent.DATA_UPDATED, sharedDataUpdated);
   }
   
   private function sharedDataUpdated(event:AppEvent):void
   {
    var dataTable:Hashtable = event.data as Hashtable;
    if (dataTable.containsKey("Some Unique Name"))
    {
     var recAC:ArrayCollection = dataTable.find("Some Unique Name") as ArrayCollection;
     var obj:Object = recAC[0];
     //do something with obj
     ta.text = obj.toString();
     dataTable.remove("Some Unique Name");
    }
   } 
  ]]>
 </mx:Script>
 <WidgetTemplate id="wTemplate">
  <mx:TextArea id="ta" width="100%" height="100%"/>
 </WidgetTemplate>
</BaseWidget>


Config.xml entries:
<widget label="Send" icon="com/esri/solutions/flexviewer/assets/images/icons/i_lego.png" menu="menuWidgets" config="">com/esri/solutions/flexviewer/widgets/SendMessageWidget.swf</widget>
  <widget label="Recieve" icon="com/esri/solutions/flexviewer/assets/images/icons/i_lego.png" menu="menuWidgets" config="">com/esri/solutions/flexviewer/widgets/MessagingWidget.swf</widget>
0 Kudos
NadirHussain
Frequent Contributor
Dear Robert
               Thanks for reply.i falow the steps according to your instructions.but
               still failed.i dont know what is going wrong.if anything else will be highly appreciated.

               Thanks once Again.


             Nadir
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Nadir,

  Did you attempt to use the provided widgets and they do not work, or are you saying that you attempted to use the concept in your own code? The example widgets are as simple as I can make, showing how messaging works. I have messaging working on my site since the first release of the SFV, so I still am not sure where you are going wrong. The only thing I can suggest is that you get the Flash Player Debugger version from the Adobe website and add breakpoints into your code to see where it is getting to and not getting to.
0 Kudos