tags:

views:

59

answers:

2

Hi Flex developers,

I'm trying to place a popup window (TitleWindow) in the middle of the main application window. how do i set the coordinates of my popup window to be of the main application window? i tried the localToGlobal function but with no luck, I just can't get the main window x and y.

Thanks in advance, Uzi.

+2  A: 

From the Adobe Docs:

Just call the centerPopUp method in the CreationComplete event of your TitleWindow.

private function handleCreationComplete():void {
  // Center the TitleWindow container 
  // over the control that created it.
  PopUpManager.centerPopUp(this);
}

If you're creating the popUp from within a method, you can also try:

public function openWindow(event:MouseEvent):void {
  myPopUp = new TextArea();
  myPopUp.width= 220;
  myPopUp.height= 150;
  myPopUp.text = "Hold down the Shift key, and " + 
    "click in the TextArea to close it.";
  myPopUp.addEventListener(MouseEvent.CLICK, closeWindow);
  PopUpManager.addPopUp(myPopUp, this, true);
  PopUpManager.centerPopUp(myPopUp);
}

Edit: You can also try:

PopUpManager.centerPopUp(Application.application as DisplayObject);

or if the component is directly on your application's main stage

PopUpManager.centerPopUp(this.parent);

Second Edit: If you're using the PopUpManager.addPopUp method to launch your popup, just change the 2nd argument from this to this.parent (or whatever component you like). The 2nd argument tells the PopUpManager what your popup's parent is. Check out the Adobe Live Docs for more info.

PopUpManager.addPopUp(myPopUp, this.parent, true);
Jason Towne
I did, but it centers the popup relatively to its parent (I forgot to mention that the main window is not the popup's parent, I have several windows within the main window). All I need is to get somehow the mian window's properties.Thanks for the answer,Uzi.
uzi orgad
I edited my answer based on your comments. In the future, if you can post some of your code it will help us come up with a more specific solution for your problem.I hope I can help! :)
Jason Towne
A: 
myPopUp.x = (Application.application.width - myPopUp.width)/2
myPopUp.y = (Application.application.height - myPopUp.height)/2
Nishu
This will work too, but why go through the extra work when the PopUpManager already gives us a method to center popups?
Jason Towne
i think PopUpManager.centerPopUp take the popUp as a parameter and not the parent. Is there something I am missing?
Nishu
When you use PopUpManager.addPopUp to create your popup, you can specify what the popup's parent control is. So when you call the centerPopUp method it will automatically center itself over its parent control.
Jason Towne
uzi orgad mentioned that the main window is not the popup's parent, he have several windows within the main window
Nishu