6 Replies Latest reply on Oct 2, 2007 1:23 AM by Karl_Sigiscar_1971

    showing PopUpManager TitleWindow in middle of the Screen

    mnarra
      Hi All,

      How to show the PopupManager TitleWindow in the middle of the screen.

      By default, the popup is set to x=0 and y=0.

      I need to show up the popup in the middle of the screen irrespective of the popup's width and height..

      how to achieve this ?
        • 1. Re: showing PopUpManager TitleWindow in middle of the Screen
          Huntsecker
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
          <mx:Script>
          <![CDATA[
          import mx.managers.PopUpManager;
          import mx.containers.TitleWindow;
          import mx.controls.TextArea;
          import mx.events.CloseEvent;


          private var _window:TitleWindow;
          private function showWindow(event:MouseEvent):void
          {
          var textArea:TextArea = new TextArea();
          textArea.text = "blah blah blah";
          textArea.width = 300;
          textArea.height = 200;
          _window = TitleWindow(PopUpManager.createPopUp(this, TitleWindow, true));
          _window.x = 300;
          _window.y = 100;
          _window.addChild(textArea);
          _window.showCloseButton = true;
          _window.addEventListener(CloseEvent.CLOSE, closeHandler);

          }
          private function closeHandler(event:CloseEvent):void
          {
          PopUpManager.removePopUp(_window);
          }


          ]]>
          </mx:Script>
          <mx:Canvas x="0" y="0" width="100%" height="100%" id="mainContainer">
          <mx:ApplicationControlBar x="0" y="0" width="100%" height="40">
          <mx:Button label="Show window" click="showWindow(event)"/>
          </mx:ApplicationControlBar>
          </mx:Canvas>
          </mx:Application>

          the above will do what you need.
          Cheers
          • 2. showing PopUpManager TitleWindow in middle of the Screen
            aceinc
            I use the following;

            var entryWindowInstance:LogEntry = LogEntry(PopUpManager.createPopUp(this, LogEntry, true));
            PopUpManager.centerPopUp(entryWindowInstance);

            Paul
            • 3. showing PopUpManager TitleWindow in middle of the Screen
              Mitek17 Level 1
              Hi Paul,

              Your code will not work in all cases as the PopUp window could be not rendered yet which makes centering useless.
              Actually, I am surprised that it works at all.

              The proper code should be like this:

              <mx:TitleWindow ....
              creationComplete="PopUpManager.centerPopUp(this);">

              Centering happens on creationComplete event, when object has been validated, measured and rendered.

              Cheers,

              Dmitri.
              • 4. Re: showing PopUpManager TitleWindow in middle of the Screen
                mnarra Level 1
                Hi ,

                Thanks for the solutions..

                I used the PopUpManager.centerPopUp(entryWindowInstance);
                And this worked fine..

                But as suggested by Huntsecker, i am not aware of the TitleWindow's width and height, based on the content it may be too large or too small..

                So the window's X and Y is causing the problem..

                centrePopUp() worked in my case.

                Regards,
                Madan N
                • 5. Re: showing PopUpManager TitleWindow in middle of the Screen
                  aceinc Level 1
                  Mitek17,

                  Actually, I have not seen it fail, and I have tested it a fair amount.

                  Paul
                  • 6. Re: showing PopUpManager TitleWindow in middle of the Screen
                    Karl_Sigiscar_1971 Level 3

                    The first parameter of the centerPopup() method is the parent of the popup window.

                    The popup will be centered relative to its parent width and height.

                    If you want to open a popup centered on the screen from another class than the main MXML, you can use mapping (a tip from Peter DeHaan blog):

                    In your application model if you use Cairngorm:
                    public var map:Object = new Object();

                    In your main on creationComplete:
                    this.model.map["app"] = this;

                    Now, when opening a popup from a secondary MXML or AS class:
                    PopUpManager.createPopUp(this.model.map["app"], TitleWindow, true));

                    This will ensure the popup is centered on the application window.

                    If you use Application.application instead of this.model.map["app"], it doesn't work.