Apache flex 中心窗组件

Apache flex 中心窗组件,apache-flex,flash,actionscript,Apache Flex,Flash,Actionscript,我已经创建了一个窗口组件,但无论我打开它的窗口,它都会随机定位,x和y位置只会偏移元素,而不会偏移窗口。如何将其定位到屏幕中央 Flex 4(AS3): 必须参照stageWidth和stageHeight属性定位新窗口 假设新窗口的原点位于左上角,则窗口的新位置将为: (Stage.stageWidth-newWindow.width)/2,(Stage.stageHeight-newWindow.height)/2 试试这个: newWindow.x = Math.ceil((Capabil

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

Flex 4(AS3):


必须参照stageWidth和stageHeight属性定位新窗口

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

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

试试这个:

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

您可以使用窗口的布局属性,如horizontalCentre和verticalCentre使用基于contstraint的布局方案

显示完整代码如何?不知道如何使用你的代码。它是否适用于“窗口”组件?请按照Michaels的回答使用它-Capabilites.screenResolutionX提供设备的屏幕大小,例如1024x768的PC屏幕。stageWidth提供页面中player元素的实际大小。赫诺。这和我的问题无关。实际上,将它添加到窗口组件中,并在每一行添加“This.nativewindow”而不是“newWindow”是可行的。newWindow是一个组件,而不是nativeWindow,对于Flex 4和AIR 2中的许多部件来说,它已经非常混乱了。Math.ceil是可选的。感谢
newWindow.x = Math.ceil((Capabilities.screenResolutionX - newWindow.width) / 2);
newWindow.y = Math.ceil((Capabilities.screenResolutionY - newWindow.height) / 2);