AIR - resizing the inner window proportionally

my application starts with a scene size of 1000 x 500, the aspect ratio is 2: 1. its own window has a system chrome, which will always be slightly higher by a few pixels.

how can only proportional changes of the own window be allowed to always maintain a 2: 1 aspect ratio at the stage?

The following code does not work as I expect:

package
{
//Imports
import flash.display.NativeWindow;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.NativeWindowBoundsEvent;

//Class
[SWF(width="1000", height="500", frameRate="60", backgroundColor="#000000")]
public class WindowTest extends Sprite
    {
    //Constants
    private static const ASPECT_RATIO:Number = 2.0; //2:1 Aspect Ratio

    //Constructor
    public function WindowTest()
        {
        init();
        }

    //Initialization
    private function init():void
        {
        stage.scaleMode = StageScaleMode.NO_SCALE;
        stage.align = StageAlign.TOP_LEFT;
        stage.nativeWindow.addEventListener(NativeWindowBoundsEvent.RESIZE, windowResizeEventHandler);
        }

    //Window Resize Event Handler
    private function windowResizeEventHandler(evt:NativeWindowBoundsEvent):void
        {
        evt.currentTarget.width = stage.stageHeight * ASPECT_RATIO;
        }
    }
}
+3
source share
1 answer

prevent the default event and resize the window manually:
EDIT: it seems that the air is calculating the width in a weird way, so to prevent flickering at the beginning, set the window size to 1050x500 in the SWF tag.

package{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.NativeWindowBoundsEvent;

//Class
[SWF(width="1000", height="500", frameRate="60", backgroundColor="#000000")]
public class airtest extends Sprite
{
    //Constants
    private static const ASPECT_RATIO:Number = 2.0; //2:1 Aspect Ratio

    //Constructor
    public function airtest()
    {
        init();
    }

    //Initialization


private function init():void
    {
        stage.scaleMode = StageScaleMode.NO_SCALE;
        stage.align = StageAlign.TOP_LEFT;
        stage.nativeWindow.addEventListener(NativeWindowBoundsEvent.RESIZING, windowResizeEventHandler);
    }

    private function windowResizeEventHandler(evt:NativeWindowBoundsEvent):void
    {
        evt.preventDefault()
        if (evt.beforeBounds.width != evt.afterBounds.width){//user resizes width
            evt.currentTarget.width = evt.afterBounds.width
            evt.currentTarget.height = evt.afterBounds.width/ASPECT_RATIO;
        } else if (evt.beforeBounds.height != evt.afterBounds.height){
            evt.currentTarget.height = evt.afterBounds.height
            evt.currentTarget.width = evt.afterBounds.height*ASPECT_RATIO;
        }

    }
}
}
+2
source

All Articles