FV 3.0 Widget Communication

1333
16
Jump to solution
08-04-2012 12:36 PM
JosephGrubbs
New Contributor III
I'm trying to get a custom addToFavs ("Add to Favorites") button in the PopUpRendererSkin to send data into the custom RequestWidget.  Any assistance would be greatly appreciated!

Joe

CODE SEGMENTS

Here's the code from the PopUpRendererSkin.  The code to initialize the Request widget is working but I'm getting a "Call to a possibly undefined method" message on the "addSharedData" line. 

private function addToFavs_clickHandler(event:MouseEvent):void
{
[INDENT]var msArr:ArrayCollection = new ArrayCollection();
  msArr.addItem("Board Name");
  msArr.addItem("Location");
  msArr.addItem("Street Side");
  msArr.addItem("Facing");
  addSharedData("MiniSearch_Search", msArr)
  //The code to initialize the Request widget if needed
  AppEvent.dispatch(AppEvent.WIDGET_RUN,ViewerContainer.getInstance().widgetManager.getWidgetId("Request Board Information"));[/INDENT]
}


Here's the code from the Request widget.  I'm not getting any errors on this code but of course cannot test it until I'm able to send the data from the PopUpRendererSkin.


protected function PopUpRendererSkin_initializeHandler(event:FlexEvent):void
{
[INDENT]AppEvent.addListener(AppEvent.DATA_PUBLISH, sharedData);
AppEvent.addListener(AppEvent.DATA_SENT, sharedData2);
fetchSharedData();[/INDENT]
}
  
private function sharedData(event:AppEvent):void
{
[INDENT]if (data.key == "MiniSearch_Search")
{
if (data.collection[0]){
com.esri.viewer.customskins.PopUpRendererSkin(data.collection[0]);[/INDENT]
}
}
}
  
private function sharedData2(event:AppEvent):void
{
[INDENT]var dataTable:Hashtable = event.data as Hashtable;
if (dataTable.containsKey("MiniSearch_Search"))
{
var recAC:ArrayCollection = dataTable.find("MiniSearch_Search") as ArrayCollection;
if (recAC[0]){
com.esri.viewer.customskins.PopUpRendererSkin(recAC[0]);[/INDENT]
}
}
}
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Joe,

   Update this:

            private function sharedDataUpdated(event:AppEvent):void             {                 if (event.data.key == "Board_Data")                 {                     if (event.data.collection[0]){                         //mailme();                         add2favs(event.data.collection[0]);                     }                 }             }

View solution in original post

0 Kudos
16 Replies
RobertScheitlin__GISP
MVP Emeritus
Joseph,

   Well there are several things here that make no sense to me... In your Request widget you need to be calling these line from the function that is called when the widgetConfigLoaded event is fired (normally called init function):

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

I tend to put them right under this line in the init:
                AppEvent.addListener(AppEvent.DATA_PUBLISH, sharedDataUpdated);


I am not sure if that what you are trying to do with the PopUpRendererSkin_initializeHandler function... but why would you call it PopUpRendererSkin_initializeHandler if it is in the Request widget?

Everything in your sharedData2 function looks OK (I would probably change the key from "MiniSearch_Search" to something more applicable to you), except this line:

com.esri.viewer.customskins.PopUpRendererSkin(recAC[0]);


What exactly is this line suppose to be doing? I looks as if you are treating PopUpRenderSkin as a function...? I think you want to replace that line with a function in your Request widget that you are wanting to call with the data that has been passed. Same comment with your sharedData function.
0 Kudos
JosephGrubbs
New Contributor III
Robert - Once again, thank you very much for your input and guidance.  I'm working with ESRI's SDK team on this issue but haven't been getting nearly the immediate response/direction that you've provided.

I've made the following changes based on your comments.  As you look at these, please keep in mind that I'm

1. Very (!) new to Flex development
2. Trying to work from your previous posts along with code recommendations from ESRI

Also, the "mailme" function is still under development but I've added that function to the sharedDataUpdated and sharedDataUpdated2 functions.

Obviously, I'm still struggling.


REQUEST WIDGET CODE:

   private function widgetConfigLoaded(event:AppEvent):void
   {
    AppEvent.addListener(AppEvent.DATA_PUBLISH, sharedDataUpdated);
    AppEvent.addListener(AppEvent.DATA_SENT, sharedDataUpdated2);
    fetchSharedData();
   }
  
   private function sharedDataUpdated(event:AppEvent):void
   {
    if (data.key == "Board_Data")
    {
     if (data.collection[0]){
      mailme();
     }
    }
   }
  
   private function sharedDataUpdated2(event:AppEvent):void
   {
    var dataTable:Hashtable = event.data as Hashtable;
    if (dataTable.containsKey("Board_Data"))
    {
     var recAC:ArrayCollection = dataTable.find("Board_Data") as ArrayCollection;
     if (recAC[0]){
      mailme();
     }
    }
   }
  
   private function mailme():void
   {
    var u:String = "";
    u+= "mailto:cartapisana@gmail.com";
    u+= "?";
    u+= "subject=";
    u+= "Board Request from " + emailSubject.text;
    u+= " ";
    u+= "&body=Request Submitted By:"
     + "%0D%0A" + "%0D%0A"
     + "Name: " + emailName.text
     + "%0D%0A"
     + "Company: " + emailSubject.text
     + "%0D%0A"
     + "Phone: " + emailPhone.text
     + "%0D%0A"
     + "Email: " + emailEmail.text
     + "%0D%0A" + "%0D%0A"
     + "Contact Me: " + contactBox.selected
     + "%0D%0A" + "%0D%0A"
     + "Comments: "
     + "%0D%0A" + "%0D%0A"
     + emailComment.text
     + "%0D%0A" + "%0D%0A"
     + "Billboards:"
     + "%0D%0A + %0D%0A"
     + emailBillboards.text
     + "%0D%0A" + "%0D%0A"
   
   }
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Joe,  Its going to be best If you post your widgets mxml code.
0 Kudos
JosephGrubbs
New Contributor III
Robert - Sounds great.  Here's the Request widget and the PopUpRendererSkin mxml files (attached).  Also, in the code segments I posted yesterday for the Request widget, I used the mailme function in the sharedDataUpdated functions.  As I'm thinking about it, I'm going to want to develop a separate function to load the shared data from the PopUpRendererSkin into the Request widget form.  This will give the user an opportunity to see all of the data (favorites) he/she has selected before clicking the Request widget form's submit button.

Again, thanks so much for all of your help!  This is the last piece before the map application goes live.  Speaking of which, would it help to see the test version of the full map application?  It can be accessed at:

www.carteroutdoor.com/carterwebmap

Thank you!

Joe
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Joe,

   OK, I have made changes to your files and tested to make sure they work and commented my changes so you can learn from them.
0 Kudos
JosephGrubbs
New Contributor III
Robert - Once again, I cannot thank you enough.  I'll integrate your changes into my code and go over your comments so that I can see how you did it.  Truly, thank you!

Joe
0 Kudos
JosephGrubbs
New Contributor III
Robert - I integrated your recommended code into my project and did not get any errors when compiling.  However, when I tested the "Add to Favorites" button to add the board data into the Request widget, I got the error message below.  Any suggestions?

Also, thank you for designing the function to populate the data for the favorites into the Request widget.  What part of the widget would the data go?  Into the Billboards box?  That's what my ultimate goal would be, so that the user could see the favorites before clicking submit.

Again, thanks so much!

Joe


TypeError: Error #1009: Cannot access a property or method of a null object reference.
at widgets.Request::RequestWidget/sharedData()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.esri.viewer::AppEvent$/dispatch()
at com.esri.viewer.customskins::PopUpRendererSkin/addSharedData()
at com.esri.viewer.customskins::PopUpRendererSkin/addToFavs_clickHandler()
at com.esri.viewer.customskins::PopUpRendererSkin/__addToFavsButton_click()
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Joe,

   So what is at line 42 in your Request widget?

What part of the widget would the data go?
??? That is up to you, and your desired workflow as the developer you would have the best knowledge of what you are attempting to do here.
0 Kudos
JosephGrubbs
New Contributor III
Robert - Line 42 in the Request widget contains just the close bracket for the sharedDataUpdated function:

private function sharedDataUpdated(event:AppEvent):void
   [INDENT]{
    if (data.key == "Board_Data")
    {
     if (data.collection[0]){
      add2favs(data.collection[0]);
     }
    }
   }[/INDENT] //The line directly above with the close bracket is line 42


Understood about the location of where the shared data come in; I'll work on that now.

Thank you!

Joe
0 Kudos