3
votes

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

4

4 Answers

5
votes

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;
0
votes

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));
0
votes
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

0
votes

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>