3 Replies Latest reply on Sep 24, 2010 7:49 AM by BhaskerChari

    dispatching events


      Hi all:


      I'm trying to figure out how to let a component know data in the previous component has changed. My first time through my application, everything works fine as long as I go forward through the app...the events fire, my main application file changes to the correct state, etc. However, if I go back and change information on one of my previous screens, I need to figure out how to tell the successive screens the information has changed and that they need to call the RemoteObjects with a new set of parameters to get updated information. I am dispatching an event from screen 2 to tell my main application file to change state from screen 2 back to screen 1, and then from screen 1 back to screen 2, but when I change my selection on screen 1, the info on screen 2 doesn't refresh.


      Here's what I've tried so far:

      1. I tried dispatching an event from my main application file to tell screen 2 my initial selection had changed, but my event handler on Screen 2 never caught the event. Can I even do that? I seem to remember reading something that said it was possible to dispatch events up the component chain (from child components up as far as the main application file), but not back down but I don't remember where I read that so I haven't yet been able to verify it for myself.
      2. I tried just re-initializing Screen 2's DataProvider with the updated info (e.g., from my main application file doing something like):
      3. if(iWentBack == true)


          screen2ComponentID.getRemoteObjectDataResult = null; //to clear out previous selection

          screen2ComponentID.getRemoteObjectDataResult.token = remoteObject.remoteFunction(newSelectionFromScreen1); //to get the updated data from my new selection



        When I try this, I do successfully clear out my previous data, but on Screen 2 I'm just getting null on my data provider (so I'm not getting updated results from my remote object call). I've also just tried calling Screen 2's init() method from the main application mxml file, but that produced the same results (null data on screen 2). Am I trying to do the impossible here?


      Thanks in advance for any suggestions!


      ~ Amanda

        • 1. Re: dispatching events
          BhaskerChari Level 4

          Hi amandamartino,


          Can you please tell what is your application structure in which you placed the screens....something like as below




               <screens:screen1 />

               <screens:screen2 />

               <screens:screen3 />



          One thing you can do here is to dispatch an event with respect to systemManager in your main application and also try to listen the event with respect to systemManager in your screen2.



          So in your main application you dispatch an Event like this..


          //In your main app

          Application.application.systemManager.dispatchEvent(new Event("mainAppDataChanged"));


          //In your Screen 2 you will listen the event w.r.t systemManger like below..

          Application.application.systemManager.addEventListener("mainAppDataChanged", onMainAppDataChanged);


          private function onMainAppDataChanged(event:Event):void


               Application.application.systemManager.removeEventListener("mainAppDataChanged", onMainAppDataChanged);


          // write your logic and update data changes here...




          Dont forget to remove the Event Listener as I did in the onMainAppDataChanged() function....


          This will make you catch the event in the screen2 dispatched from the main app...



          If this post answers your question or helps, please kindly mark it as such.


          Bhasker Chari

          • 2. Re: dispatching events
            amandamartino Level 1

            That did it. Thank you so much, Bhasker! (And sorry about the delay in responding; this portion of the project got put on hold for a bit and I've only gotten back to it in the last couple days).


            ~ Amanda

            • 3. Re: dispatching events
              BhaskerChari Level 4

              Its ok Amanda no problem..I am glad that it worked for you....