3

I'm designing a desktop app with Adobe Flash CS6, using air 3.2 for desktop (in flash target setting). In air settings, there's an advanced tab which makes it possible to set the initial value for the position of the app's window. I don't know how I should set it to the middle of the screen.

here's a screenshot:

enter image description here

Milad
  • 1,239
  • 3
  • 19
  • 37

4 Answers4

5

Dont use these properties, just add code to your app:

stage.nativeWindow.x = (Capabilities.screenResolutionX - this.width)*0.5;
stage.nativeWindow.y = (Capabilities.screenResolutionY - this.height)*0.5;
Serge Him
  • 936
  • 6
  • 8
0

For a HTML/JS-based AIR project, you can use:

window.moveTo(Math.round((window.screen.availWidth - window.outerWidth) / 2), Math.round((window.screen.availHeight - window.outerHeight) / 2));
Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
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;

Works for me

Panoman
  • 387
  • 3
  • 7
  • Hi, could you please add some explanation to your code? This popped up in the review queue, as code-only answers tend to. – Will Jun 19 '16 at 07:37
0

If you're using FlashBuilder, or an MXML file for a WindowedApplication, you can do it this way, in the initialization handler. This uses the initial dimensions of the application (defined in the application.xml file) read from the bounds of the nativeWindow. [MXML file contents]

<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>
Derek Wade
  • 697
  • 8
  • 11