tags:

views:

238

answers:

1

How can I center a popup in Flex 3.4+?

In Flex 3.1, I could center a pop-up over its parent by setting its parent in the createPopup, then using centerPopup. In Flex 3.4 and 3.5, the window appears with its upper left corner matching the upper left of its parent... even after the centerPopup.

Is there a work-around? or am I not using centerPopup as intended?

A: 

for now, I'm using the following function, stuck into my static WindowUtils class:

  // work-around for broken PopupManger.centerPopup in Flex 3.4 and 3.5
  public static function centerPopup(popup: UIComponent, centerOn: UIComponent): void
  {
     var pt:Point = new Point(0, 0);
     pt = centerOn.localToGlobal(pt); // Convert local 0,0 into global coordinate
     pt = popup.globalToLocal(pt); // Convert the result into local coordinate of myPop
     popup.move(Math.round((centerOn.width - popup.width) / 2) + pt.x,
      Math.round((centerOn.height - popup.height) / 2) + pt.y);
  }
Jim Carroll