中心窗口组件

时间:2010-12-06 06:59:56

标签: flex flash actionscript

我已经创建了一个窗口组件,但它会随机定位我是否打开它的窗口,x和y位置只会偏移元素,而不是窗口。如何将其放置在屏幕中央?

Flex 4(AS3):

private function openDoc():void {
    if (newWindow != null) newWindow.close();
    newWindow = new docwin();
    newWindow.width = 500;
    newWindow.height = 320;
    newWindow.type = "normal";
    newWindow.systemChrome = "standard";
    newWindow.transparent = false;
    newWindow.setStyle("showFlexChrome", true);
    newWindow.showStatusBar = false;
    newWindow.minimizable = false;
    newWindow.maximizable = false;
    newWindow.resizable = false;
    newWindow.open();
}

3 个答案:

答案 0 :(得分:1)

试试这个:

newWindow.x = Math.ceil((Capabilities.screenResolutionX - newWindow.width) / 2);
newWindow.y = Math.ceil((Capabilities.screenResolutionY - newWindow.height) / 2);

答案 1 :(得分:1)

您可以使用窗口的布局属性,如水平中心和垂直中心使用约束的布局方案

答案 2 :(得分:0)

您必须参考stageWidth和stageHeight属性来定位新窗口。

假设新窗口的原点位于左上角,则窗口的新位置为:

(Stage.stageWidth - newWindow.width)/ 2,(Stage.stageHeight - newWindow.height)/ 2;

相关问题