4 Replies Latest reply on Feb 17, 2012 7:50 AM by Zolotoj

    Passing data between two popups

    Zolotoj Level 3

      I have one popup that open another one. When I close second popup I want to execute a function on first popup.

      I am trying something like this but it's not working:

      1 popup:
      this.addEventListener("changeCoverageValidationEvent", coverageDispositionChangeServiceCall);

       

      private function coverageDispositionChangeServiceCall(event:Event=null):void

      {

      ..............

      }

       

      2 popup

      var changeCoverageValidationEvent:Event = new Event("changeCoverageValidationEvent", true, false);

      dispatchEvent(changeCoverageValidationEvent);  

       

       

      Dont see coverageDispositionChangeServiceCall being fired.

       

      Thanks

        • 1. Re: Passing data between two popups
          Ansury Level 3

          A little "cheat" trick I like to do is pass a callback function.  I actually prefer doing this to events, because it lets you take advantage of Flash Builder features.  (F3 takes you immediately to the function definition, also it's much easier to determine where your "listener" code is.  Annoying to have some event firing and causing something to happen you didn't expect, and having to do a text search to find out where.)  One possible downside is forgetting to set the callback (but you could also forget to add an event listener).  The main downside being perhaps that it's not particularly object oriented.  But then, who cares about blindingly adhering to design paradigms if it gets the job done better?

           

          Ex.

           

          2nd dialog:

          public var callback:Function;
          
          private function closeHandler():void {
               if (callback != null) //You may want to skip the null check, or even throw an Error here if a callback is mandatory to the component's use
                     callback(passAnyVars, orWhatever, asNeeded);
          }
          
          

           

          1st dialog:

           

          public function someHandler(var1:String, whatever:String, blah:int):void {
               //Do whatever you want to do
          }
          

           

          Container or whatever is creating these dialogs:

           

          var dialog1:Dialog = //PopupManager boilerplate...
          var dialog2:Dialog = //PopupManager boilerplate...
          
          
          
          dialog2.callback = dialog1.someHandler;
          
          

           

          Or alternatively:

           

           

          ...
          
               var dialog1:Dialog = //PopupManager boilerplate...
               var dialog2:Dialog = //PopupManager boilerplate...
               
          
               dialog2.callback = anotherHandler;
          
          }
          
          
          
          
          public function anotherHandler(var1:String, whatever:String, blah:int):void {
          
               dialog1.someHandler(var1, whatever, blah); //dialog1 would have to be within scope of course, not like I have in the above example..
          }
          
          
          • 2. Re: Passing data between two popups
            Zolotoj Level 3

            No, I need to use events.

            • 3. Re: Passing data between two popups
              Claudiu Ursica Level 4

              This is dirty but will probably get you there.

              You have a systemManager ref in both popups. Used it as a shared event dispatched, it is the same reference after all....

               

               

              • 4. Re: Passing data between two popups
                Zolotoj Level 3

                Container or whatever is creating these dialogs:

                 

                var dialog1:Dialog = //PopupManager boilerplate... 
                var dialog2:Dialog = //PopupManager boilerplate...      
                dialog2.callback = dialog1.someHandler;

                That's not how it works in my case. 1st popup creates second.