2 Replies Latest reply on Jul 25, 2009 12:08 PM by niff111

    Passing data from popUp to its parent component

    niff111

      I'm creating a popUp window:

      var popUpWindow:IFlexDisplayObject = PopUpManager.createPopUp(this, addBook, false);
      PopUpManager.centerPopUp(popUpWindow);
      

      In addBook.mxml component I've created dispatcher, like in this example http://stackoverflow.com/questions/473093/passing-values-between-custom-components-in-flex -mxml

      and when I'm creating this addBook component by

      <components:addBook buttonClicked = "myComponent_buttonClicked(event)"/>
      

      (like in this example) passing data works fine.

       

      I'm wondering how to do that with my popUp window. Is there any possibility to add this "buttonClicked" property when I'm creating window in ActionScript?

       

      Thank you,

      niff

        • 1. Re: Passing data from popUp to its parent component
          injpix Level 3

          The best way, in my opinion and several others, would be to use Flex's event model.  Simply dispatching an event and have your parent component listen for it.  And also you can bundle data in this event.

           

          Below is a snippet from one of my previous projects.  So as you may notice, their is a button in my popup with an instance name of submitButton.  From my parent component, I am listening specfically for a MouseEvent.CLICK event for I can pass that event in handler called submitData.  From within submitData, you can then cast that event to a custom type to access its properties, as I have below.  Or just access its default Event's data property.

              
                      private function menuBarHandler(event:MenuEvent):void
                      {
                              popUp = PopUpManager.createPopUp( this, AddPopUp , true) as AddPopUp;
                              PopUpManager.centerPopUp(popUp);
                               
                              popUp.submitButton.addEventListener(MouseEvent.CLICK, submitData);
                              
                              popUp.addEventListener("close", addPopUpCloseHandler);
                      }
                      
                      private function submitData(event:Event):void
                      {
                          var rEvent:RosterViewEvent     = new RosterViewEvent(RosterViewEvent.ADD_CONTACT);
                          rEvent.data.jid             = popUp.contactName.text.toString();
                          dispatchEvent( rEvent );
                          
                          addPopUpCloseHandler(event);
                      }
          
          • 2. Re: Passing data from popUp to its parent component
            niff111 Level 1

            Thanks a lot!

            You saved me. I had serious mistakes in my code, but now it's working.

             

            Greets,

            niff