开发者

Placing popup window in the middle of the main window

I'm trying to place a popup window开发者_如何学Go (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.


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);


myPopUp.x = (Application.application.width - myPopUp.width)/2
myPopUp.y = (Application.application.height - myPopUp.height)/2


@uzi orgad I think this will be suitable for you, try this

var popup:Object ;
popup = PopUpManager.createPopUp(
                         FlexGlobals.topLevelApplication as DisplayObject, 
                         popupname, true);
PopUpManager.centerPopUp(popup as mx.core.IFlexDisplayObject);

FlexGlobals.topLevelApplication as DisplayObject points to the main application.So the popup appears at the middle of the application

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜