Search code examples
androidactionscript-3flashairflash-builder

AS3 Stage changing by itself, how is it possible?


I'm developing an Air App for Android. It was going very well when it occurred. Let me explain a bit more: I run the app, everything is ok: the stageWidth is 800 as I've defined before. (I know that is impossible to set stageWidth at runtime and that stageWidth and stageHeight is read only. I press back/home button and my application loses focus normally, but when I open application again either by recent list apps or menu apps, the stageWidth changes by itself to 1794. I really don't know why this number and not even do not know how is possible alter stageWidth.


Solution

  • Capabilities.screenResolutionX and Capabilities.screenResolutionY are what you should use for screen width and height on apps. Note: they don't change with rotation - they'll stay the same when screen rotates, so your code will look something like this:

    if (bStagePortrait) {
        iScreenWidth = Capabilities.screenResolutionX;
        iScreenHeight = Capabilities.screenResolutionY;
    } else {
        iScreenWidth = Capabilities.screenResolutionY;
        iScreenHeight = Capabilities.screenResolutionX;
    }
    

    Use this code in app to keep app from stretching and in left corner:

    stage.align = StageAlign.TOP_LEFT;
    stage.scaleMode = StageScaleMode.NO_SCALE;
    

    If you make those changes, you should start seeing good numbers.