Adobe Air - Flash - 初始窗口位置

3
我正在使用 Adobe Flash CS6 设计一款桌面应用程序,使用 Air 3.2 for desktop(在 flash target setting 中)。 在 Air 设置中,有一个高级选项卡,可以设置应用程序窗口位置的初始值。 我不知道该如何将其设置为屏幕中央。
以下是截图:

enter image description here

4个回答

5
不要使用这些属性,只需在应用程序中添加代码即可:
stage.nativeWindow.x = (Capabilities.screenResolutionX - this.width)*0.5;
stage.nativeWindow.y = (Capabilities.screenResolutionY - this.height)*0.5;

谢谢!只是一个小改动...在第二行,应该是高度。 :D - Milad

0
如果您正在使用FlashBuilder或WindowedApplication的MXML文件,您可以在初始化处理程序中以这种方式完成。这将使用应用程序的初始尺寸(在application.xml文件中定义)从nativeWindow的边界读取。 [MXML文件内容]
<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>

0

对于基于HTML/JS的AIR项目,您可以使用:

window.moveTo(Math.round((window.screen.availWidth - window.outerWidth) / 2), Math.round((window.screen.availHeight - window.outerHeight) / 2));

0
var screenBounds:Rectangle = Screen.mainScreen.bounds;
stage.nativeWindow.x = (screenBounds.width - stage.nativeWindow.width) / 2;
stage.nativeWindow.y = (screenBounds.height - stage.nativeWindow.height) / 2;

对我来说可行


您好,能否请您为您的代码添加一些解释说明?这样才能够通过审核队列,因为仅有代码的回答有点不够完整。 - Will

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接