5 Replies Latest reply on Jun 12, 2009 1:18 AM by SilverFox64

    Transfering data between cascading popups

    curtisa2 Level 1

      Hi,

      Is it possible to pass data between multiple cascading popups ? I know how to pass back to the parentApplication but not the parentPopUp so-to-speak.

       

      The setup I have is that my parent application tiggers a popup (say PopUp A) and that in turn triggers another popup (PopUp B). I want to pass the results of the calculations done in popup B back to popup A. (The popups are all in separate .mxml files).

       

      Can this be done easily ?

       

      Thanks,

      Alex

        • 1. Re: Transfering data between cascading popups
          *Prashant Shelke* Level 4

          See following structure:

           

          Main Application

                    --> PopUp A (it has, var parent:Object; before popping up A you can set popUpA.parent = this; )                // here this is Main Application

                               -->    PopUp B (it has, var parent:Object; before popping up B you can set popUpB.parent = this; )          // here this is PopUpA

           

          So after making calculation you can set it to any variable or control on its parent.

           

          Thanks.

          • 2. Re: Transfering data between cascading popups
            curtisa2 Level 1

            I thought that was what I had ... namely,

             

            In mainApp.mxml ...

             

                        private var popUpA:IFlexDisplayObject;

             

                        popUpA = PopUpManager.createPopUp(this, popUpAmxmlFile, true);
                        PopUpManager.centerPopUp(popUpA);

             

             

            then in popup A ...

             

                           popUpB = PopUpManager.createPopUp(this, popUpBmxmlFile, true);

                           PopUpManager.centerPopUp(popUpB);

             

            But then in popup B the line ...

             

                           parentApplication.myPublicFn();

             

            causes the app to look for 'myPublicFn' in the mainApp, not popup A

             

             

            Is my logic messed up ?

             

            Thanks for the help

            • 3. Re: Transfering data between cascading popups
              leybniz Level 4

              Best solution for your difficulty from the root - would be  to store all calculation results, all data model in one spot/place say using some

              singleton class, which you could access then from anywhere in the code.

               

                   public class CentralModelLocator {
              
                        private static var instance : CentralModelLocator;
              
                        public var anyData:*;
              
              
                        function CentralModelLocator() {
              
                             if (instance) {
                                  throw new Error(
                                       'Singleton already created', 
                                       getQualifiedClassName(this));
                             }
                             instance = this;
                             
                        }
              
                        public static function getInstance():CentralModelLocator { 
                             if (!instance)
                                  instance = new CentralModelLocator();
              
                             return instance;
                        }
              
                   }
              
              
              

              Then you could access your data from any popup of any depth, just use this code:

              Inside PopupA code write to this var

              CentralModelLocator.getInstance().anyData = 'Some calculation result';

               

              Inside PopupB use this one code to get the result:

              CentralModelLocator.getInstance().anyData

               

              • 4. Re: Transfering data between cascading popups
                *Prashant Shelke* Level 4

                parentApplication will referr to the main Application context. You can try by storting this of Parent --> Child1 --> Child2 ..so on, as shown in previous flow, this will work for u.

                • 5. Re: Transfering data between cascading popups
                  SilverFox64

                  I have this scenario in the project I am currently working on. The solution I used was to add an event listener to PopUpB when creating it in PopUpA:

                   

                  var popUpB:PopUpB = PopUpB(PopUpManager.createPopUp(this, PopUpB, true, null));

                  popUpB.addEventListener(DataEvent.TYPE, eventHandlerFunction,false,0,true);

                  PopUpManager.centerPopUp(popUpB);

                   

                  The DataEvent is a user defined Event and contains the data required by PopUpA.

                   

                  All I have to do then is dispatch the event along with the data from PopUpB.

                   

                  dispatchEvent(new DataEvent(dataRequired, DataEvent.TYPE, true, false));

                  1 person found this helpful