Centering a PopUp in Flex

Tagged Under :

If you are using PopUpManager and TitleWindow to create a popup window in Flex, you have probably run across this problem already. The createPopup() function takes first argument as the owner of the popup window. And when you do PopUpManager.centerPopup(this) , it centers the popup. But it only centers the popup relative to its parent component, which means if you are creating the popUp from lets say a Sidebar control, the popup will not be in the center of the page but in the center of the sidebar which can look messy.

Here is what you can do to solve this.

Instead of the above, you can do this :-

I have used _class here to represent the actual TitleWindow classs you will be using. And notice how I pass the parentApplication as a UIComponent to the owner of the popup.
What this does is, it changes the owner of the PopUp to the main Application file which in return centers the Popup in the page when you call PopUpManager.centerPopUp(this).

Comments:

4 Responses to “Centering a PopUp in Flex”


  1. I’ve been trying to figure this out for a few hours now and it’s been driving me crazy! I use popup components all the time and I normally parent them to the application, but I guess this time I didn’t and it was the root of all my confusion. Thanks for the reminder! Moral of the story: you probably don’t want to create a popup on anything but the Application.application (or this.parentApplication).


  2. Yup, thats true. When I first worked on it, I spent a couple hours as well. Its just one of those things!


  3. This is just what I was looking for… gone are the days of the popup centering in my datagrid cell :D


  4. good info, thanks!

Leave a Reply