我正在使用 Adobe Flash CS6 设计一款桌面应用程序,使用 Air 3.2 for desktop(在 flash target setting 中)。 在 Air 设置中,有一个高级选项卡,可以设置应用程序窗口位置的初始值。 我不知道该如何将其设置为屏幕中央。
以下是截图:
以下是截图:
stage.nativeWindow.x = (Capabilities.screenResolutionX - this.width)*0.5;
stage.nativeWindow.y = (Capabilities.screenResolutionY - this.height)*0.5;
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:local="*"
initialize="windowedapplication1_initializeHandler(event)"
>
<fx:Script>
<![CDATA[
protected function windowedapplication1_initializeHandler(event:FlexEvent):void
{
var w:int = Capabilities.screenResolutionX;
var h:int = Capabilities.screenResolutionY;
nativeWindow.x = (w - nativeWindow.bounds.width)*0.5;
nativeWindow.y = (h - nativeWindow.bounds.height)*0.5;
}
]]>
</fx:Script>
</s:WindowedApplication>
对于基于HTML/JS的AIR项目,您可以使用:
window.moveTo(Math.round((window.screen.availWidth - window.outerWidth) / 2), Math.round((window.screen.availHeight - window.outerHeight) / 2));
var screenBounds:Rectangle = Screen.mainScreen.bounds;
stage.nativeWindow.x = (screenBounds.width - stage.nativeWindow.width) / 2;
stage.nativeWindow.y = (screenBounds.height - stage.nativeWindow.height) / 2;
对我来说可行