Search code examples
actionscript-3actionscriptsizestage

Retrieve original stage width and height after scale


Does anyone know how I can retrieve the "ORIGINAL" stage height and width that was set during compile of an Air/Flash Application

I have set the Application to compile to 1920x1080;

I have stage.scaleMode = StageScaleMode.SHOW_ALL;

and stage.nativeWindow.maximize();

But when I trace stage.stageWidth I get 1280 which is the resolution of the screen.

I was hoping to get the 1920.

I cannot use stage.width or stage.getBounds(stage) because this returns 6000. Due to items being masked off screen.

With the stage.stageWidth being the screen resolution, I was hoping I could use that and mathematically work out the original using stage.scaleX. but even with SHOW_ALL scaling the entire application, stage.scaleX returns 1.

I would love to hardcode 1920x1080 into the application, but this code is being used in multiple applications of various dimensions. And now I have become stumped.

Any help would be welcome.

EDIT: I know what "Show all" does, you do not need to tell me about it.

I also know what stage.width and stage.stageWidth do, but stage.stageWidth is returning what I believe is incorrect in this example and need an alternative.

Resize does not help either as I need it after the fact.


Solution

  • when you are setting:

    stage.scaleMode = StageScaleMode.SHOW_ALL;
    

    the Event.RESIZE is not beeing dispatched from the stage, because no RESIZE of the stage is happening.

    stage.width - is the parameter which gives you the size of all the display objects placed on it ( imagine everything what is places on the stage as a one MC ).

    stage.stageWidth - this parameter will give you back the default width only ( because no REIZE is happening, since you have scaleMode=SHOWALL, normally it does return the visible flash stage size.

    If you want to get the size of a screen ( device rezolution ):

    Capabilities.screenResolutionX
    

    SHOW_ALL parameter for scaleMode says application to stretch to the flash display size.

    If you want to change something for different sizes of the screen / flash display stage, you need to use NO_SCALE property.

    p.s. for width parameter same rules applies.

    UPDATE

    After some testing found a solution for it:

    stage.scaleMode = StageScaleMode.NO_SCALE; // reseting the scale to get actual width
    ACTUAL_STAGE_WIDTH = stage.stageWidth; // this is where you getting the width you need
    stage.scaleMode = StageScaleMode.SHOW_ALL; // setting back the scale.