13 Replies Latest reply on Jul 1, 2010 7:42 AM by UbuntuPenguin

    Reference parent

    Francisc Level 3

      Hello!

      If I open a window using the PopUpManager class, is there anyway to reference the opener from the window as to be able to call functions from the opener from insde the window?

       

      e.g. opener.someMethod();

        • 1. Re: Reference parent
          rootsounds Level 4

          Pass it through a property or constructor of the popup window class.

          • 2. Re: Reference parent
            Dajji Level 3

            How are you opening the popup? Are you using PopupManager? If yes then PopupManager's createPopup method takes first parameter for parent. You can pass that parameter.

            • 3. Re: Reference parent
              Dajji Level 3

              Sorry, I missed that you are already using PopupManager. So you can pass parent as parameter in createPopup method.

              • 4. Re: Reference parent
                Francisc Level 3

                I am passing the parrent.

                 

                How should I reference that if it works?

                 

                parentDocument?

                • 5. Re: Reference parent
                  rootsounds Level 4

                  The documentation says that the parent parameter is used by SystemManager to position the popup and such, but is not necessarily the actual parent of the popup. I don't see any way of actually retrieving what you pass in there.

                  • 6. Re: Reference parent
                    UbuntuPenguin Level 4

                    Here is what I do , when I need something like that.  But I may not be understanding your situation correctly.  Your mileage may vary.  Also , this is just an example , I retrieve popups a little differently so I only create them and add listeners once.

                     

                    <Group id="parentGroup">

                    <Script>

                        public function openPopup( event:Event ):void

                        {

                              var popup:PopUpView = new PopUpView():

                              popup.addEventListener( SmileEvent.Smiles , smileEventHandler );

                              PopUpManager.addPopUp( popup );

                              PopUpManager.centerPopUp( popup );

                        }

                     

                        public function smileEventHandler( event:SmileEvent ):void

                        {

                             this.someMethod();

                        }

                     

                    ...

                    </Group>

                     

                    PopUp.mxml

                     

                    <Script>

                       public function smileClick( event:Event  ):void

                       {

                             ///dispatch event here

                       }

                     

                    If this post was helpful please mark it as such.

                     

                    Sincerley ,

                    Ubu

                    • 7. Re: Reference parent
                      rootsounds Level 4

                      I agree that it's definitely better to use events. Clearner design and makes it more portable. It's what I generally do.

                      • 8. Re: Reference parent
                        Francisc Level 3

                        That's a very good idea. I used to do that in Flex 3, guess I forgot about it.

                         

                        Thank you!

                        • 9. Re: Reference parent
                          UbuntuPenguin Level 4

                          You are welcome ...

                          • 10. Re: Reference parent
                            BhaskerChari Level 4

                            Hi Mash,

                             

                            You can also try this without use of events...

                             

                            So you open the popup from the opener as below:

                             

                            YourOpener.mxml

                             

                            private function openPopUp():void
                            {
                                popUpComp = new PopUpComp();
                                popUpComp  = PopUpComp(PopUpManager.createPopUp(Application.application as DisplayObject,PopUpComp,true));
                               
                                popUpComp .opener = this;

                                PopUpManager.centerPopUp(popUpComp );
                            }

                             

                            public function someFunction():void

                            {

                            // This function you can call from your PopUp comp

                            }

                             

                             

                             

                            ////////In your PopUpComp.mxml.....you can have a variable for YourOpener.mxml declared......

                             

                            public var opener:YourOpener;

                             

                            Since you have set the reference for your opener in the openPopUp() function in YourOpener.mxml

                             

                            You can now use variable opener to access the public methods in your opener window as below:

                             

                            opener.someFunction();

                             

                             

                            Thanks,

                            Bhasker Chari

                            1 person found this helpful
                            • 11. Re: Reference parent
                              Sebastien V. Level 3

                              As rootsounds previously said, it's better to use event listeners. The pop up component should not be aware of its parent (or opener) type. Using events allows the pop up to be used from any component.

                               

                              So by using events you increase your code reusability and decrease the pop up/parent classes coupling.

                              1 person found this helpful
                              • 12. Re: Reference parent
                                Francisc Level 3

                                Thank you.

                                • 13. Re: Reference parent
                                  UbuntuPenguin Level 4

                                  *Ahem*