Centering a pop up window when a Flex application is resized

by Peter deHaan on April 6, 2008

in Alert, PopUpManager, PopUpMenuButton, Resize

The following example shows how you can center a pop up window (in this case an Alert control) when the Flex application is resized by using the resize event on the <mx:Application /> tag and using the static PopUpManager.centerPopUp() method.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/04/06/centering-a-pop-up-window-when-a-flex-application-is-resized/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        resize="application_resize(event);">

    <mx:Script>
        <![CDATA[
            import mx.events.ResizeEvent;
            import mx.controls.Alert;
            import mx.managers.PopUpManager;

            private var alert:Alert;

            private function init():void {
                alert = Alert.show("The quick brown fox jumped over the lazy dog.", "title");
            }

            private function application_resize(evt:ResizeEvent):void {
                if (alert) {
                    PopUpManager.centerPopUp(alert);
                }
            }
        ]]>
    </mx:Script>

    <mx:ApplicationControlBar dock="true">
        <mx:Button label="Launch!" click="init();" />
    </mx:ApplicationControlBar>

</mx:Application>

View source is enabled in the following example. | Click here to open example in a new window

{ 11 comments… read them below or add one }

1 eternalko April 7, 2008 at 12:12 pm

Nice

Reply

2 Andres April 23, 2008 at 5:55 pm

Hi,

Good example, but is it possible to use this kind of popup to enter information, or is it just for messages? If not, what would you recommend for user input?

Reply

3 peterd April 23, 2008 at 6:09 pm

Andres,

I would probably use the TitleWindow container and PopUpManager class.

Peter

Reply

4 Andres April 24, 2008 at 7:32 pm

Thanx! Those were exacly the classes I was looking for!

Great Examples!!!

Reply

5 Shane July 16, 2008 at 1:05 pm

Nice solution. Worked well for me. Thanks!

Reply

6 Abhilash November 17, 2008 at 9:56 pm

I have a form designed using Flex. The form does not fit the screen area and hence I am having scroll bars in it. When we click on some of the controls in the form, we open popups. But when the popup is opened, if we scroll the form using the form scroll bar then the popup is not getting scrolled. I want the popup to be scrolled along with the form elements. Please let me know how this can be done.

Thanks

Abhilash

Reply

7 David January 26, 2009 at 6:59 am

I have the same problem as Abhilash. Anyone have any answers?

Reply

8 Anonymous June 24, 2009 at 12:06 am

I too have the same problem. Is there any solution..?

Reply

9 Marcelo Salinas October 29, 2009 at 12:32 pm

Nice example !!!.

One Comment, the correct phrase is “The quick brown fox jumps over the lazy dog”

Reply

10 Peter deHaan October 29, 2009 at 1:17 pm

:)
Thanks, I actually had it wrong for quite a few months before I realized I was using the incorrect phrase.

Peter

Reply

11 Anonymous November 18, 2009 at 10:19 pm

I created a login window,its a pop up window. How do i enable the scroll bar for pop up window(i.e login window) when i resize the browser?

Suman

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree

Previous post:

Next post: