2010-01-14 48 views
1

如何在Flex 3.4 +中居中彈出窗口?升級到Flex 3.4並嘗試3.5 PopupManager.centerPopup破碎?

在Flex 3.1中,我可以通過將其父項設置在createPopup中,然後使用centerPopup將彈出窗口居中放在其父窗口上。在Flex 3.4和3.5中,即使在centerPopup之後,窗口的左上角也會與其父級的左上角相匹配。

是否有解決方法?或者我沒有按照預期使用centerPopup?

回答

0

現在,我使用下面的函數,堅持到我的靜態WindowUtils類:

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