7 Replies Latest reply on Apr 25, 2007 9:11 AM by parallaxed

    Center a Title Window PopUp?

    flashgruven Level 1
      How do you center a title window popup when it is bigger than it's parent Display Object?

      Is there an easy way to find the root application Display Object??

        • 1. Re: Center a Title Window PopUp?
          peterent Level 2
          Use PopUpManager.centerPopUp( popup ).
          • 2. Re: Center a Title Window PopUp?
            flashgruven Level 1
            That doesn't work in my situation... perhaps I didn't describe the problem fully.

            The containment hierarchy is:
            mx.Application // 1024 x 768
            mx:HDividedBox // 100% x 100%
            mx:Canvas // 180 wide 100% height
            mx:ViewStack // 100% x 100%
            mx:VBox // 100% x 100%
            mx:ControlBox // <=== this container has a mx:Button click="createPopUp"

            var tw = PopUpManager.createPopUp(this.parent.parent.parent , DealershipEditor, true) as TitleWindow; // parentDisplayObject!!!

            if the first parameter to createPopUp() is this, then the popup centers on ControlBox which isn't wide enough.

            I have found that if I pass in this.parent.parent.parent.parent to createPopUp() as the first parameter, then it works the way I want.

            The problem is... if I ever change the containment hierarchy, then this.parent.parent.parent may not work.

            In other environments we walk up the containment hierarchy until parent is null... but I couldn't get that to work.

            So, my question might be answered best with, is there a way to find the 'root' DisplayObjectContainer (application screen) so that the Title Window popup will center on the full application?

            When I tried using the stage as the first parameter, the popUp never showed.

            • 3. Re: Center a Title Window PopUp?

              public var tw:TileWindow;
              tw = TitleWindow( PopUpManager.createPopUp(this , DealershipEditor, true)
              tw =TitleWindow( PopUpManager.centerPopUp(tw));
              • 4. Re: Center a Title Window PopUp?
                If your overall application is more complicated, and you want pop ups to appear under (possible) multiple instances of other components, you may want to look into Caringorm's ViewHelper/ViewLocator pattern.


                It would be a good move to implement that if things have the potential to get complex.

                A simple solution would be to keep a static variable in your root component that you can reference from other components when creating your centered PopUps.

                So do something like:

                <mx:Application ...[ blarg ]
                initialize="{PopUpRoot.view = this.document}">
                public static var view:Object = null;

                Then when you call PopUpManager.createPopUp() from anywhere in your application, pass it:

                PopUpManager.createPopUp(PopUpRoot.view as DisplayObject,MyPopUpClass);

                FYI, you can call PopUpManger.centrePopUp(this) in the creationComplete event handler of MyPopUpClass.

                • 5. Center a Title Window PopUp?
                  flashgruven Level 1
                  Thanks * 5 parallaxed!

                  Turns out, I have a Global object that I create at my Application level and make available thru a getter() accessor... so, I saw your response, and added the PopUpRoot to it and started to test and found that every DisplayObject (actually, UIComponent) has a property parrentApplication and that seems to work if I cast it to a DisplayObject like so:
                  PopUpManager.createPopUp(DisplayObject(this.parentApplication) ,...

                  I will check out Cairngorm's ViewHelper pattern.

                  AND, thanks for the centerPopUp trick! I've added a creationComplete event handler and encapsulated the centering functionality where it belongs.

                  Thanks again,
                  • 6. Re: Center a Title Window PopUp?
                    peterent Level 2
                    All UIComponent-based classes have the parentApplication property. It is typed as Object because it may not always be a mx.core.Application object (in some future version of Flex/Apollo) so you have to cast to a DisplayObject.

                    The static, Application.application, is also an Object for the same reason.
                    • 7. Re: Center a Title Window PopUp?
                      parallaxed Level 1

                      Originally posted by: peterent
                      All UIComponent-based classes have the parentApplication property.

                      Smashing :-)

                      So you don't *need* to set a static var if the root is the Application itself.

                      Although if your pop up root is another component within the Application, then the above trick might come in handy for a quick solution.