Setting AIR window size whilst ignoring chrome

You specify the size of the initial window of your AIR application within an application descriptor file, like below:

<?xml version="1.0"?>
<application xmlns="http://ns.adobe.com/air/application/1.0">
    :
    :
    <initialWindow>
	<title>MyWindow</title>
        <content>main.swf</content>
        <width>800</width>
        <height>600</height>
    </initialWindow>
    :
</application>

However, the width and height you give here won't be the width and height of the stage you end up with, because your AIR window includes chrome - i.e. the window borders, titlebar, buttons etc. The size you actually get for your stage, given the application descriptor above, would be 800 - (2 x window border) by 600 - (2 x window border + title bar). Or slightly smaller than you might want, and slightly out of proportion.

The following quick hack gets around it. The idea is that, within your AIR app, you read the required width and height from your app descriptor file and adjust the stage size to fit; your app's window will inflate accordingly.

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
    xmlns:mx="http://www.adobe.com/2006/mxml"
    windowComplete="onWindowComplete()">
    <mx:Script><![CDATA[
 
    private function onWindowComplete():void
    {
        /** This function grabs the desired app size from the application descriptor
        * file, and sets the stage size to that - because the standard AIR size includes
        * chrome.
        */
        var appDescriptor:XML = XML(nativeApplication.applicationDescriptor);
        var ns:Namespace = xml.namespace();
 
        var appWidth:int=parseInt(appDescriptor.ns::initialWindow.ns::width);
        var appHeight:int = parseInt(appDescriptor.ns::initialWindow.ns::height);
 
        stage.stageWidth = appWidth;
        stage.stageHeight = appHeight;
    }
 
    ]]></mx:Script>
    <!-- Application contents goes here -->
</mx:WindowedApplication>