【问题标题】:Adobe Air - Flash - Initial window positionAdobe Air - Flash - 初始窗口位置
【发布时间】:2013-01-31 20:35:11
【问题描述】:

我正在设计一个带有 Adob​​e Flash CS6 的桌面应用程序,使用 air 3.2 for desktop(在 Flash 目标设置中)。在空中设置中,有一个高级选项卡,可以设置应用程序窗口位置的初始值。我不知道我应该如何将它设置到屏幕中间。

这是一个截图:

【问题讨论】:

    标签: flash air window-position


    【解决方案1】:

    不要使用这些属性,只需将代码添加到您的应用:

    stage.nativeWindow.x = (Capabilities.screenResolutionX - this.width)*0.5;
    stage.nativeWindow.y = (Capabilities.screenResolutionY - this.height)*0.5;
    

    【讨论】:

    • 谢谢!虽然只是一个小改动......在第二行,它应该是高度。 :D
    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:
      var screenBounds:Rectangle = Screen.mainScreen.bounds;
      stage.nativeWindow.x = (screenBounds.width - stage.nativeWindow.width) / 2;
      stage.nativeWindow.y = (screenBounds.height - stage.nativeWindow.height) / 2;
      

      为我工作

      【讨论】:

      • 嗨,您能在您的代码中添加一些解释吗?这会在审核队列中弹出,因为只有代码的答案往往如此。
      【解决方案4】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-12-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-28
        • 1970-01-01
        相关资源
        最近更新 更多