How to Determine and Set Screen Size at run time using action script?

时光怂恿深爱的人放手 提交于 2019-12-12 01:46:41

问题


Hey so i am developing an android application using action script(the adobe air one) since the screen size of my .swf application is appox 840X480... Can i detect the screen size of the android device running application at runtime and set the screen size accordingly?? if so How?? P.S - I'm still rookie at Action-script Thank You


回答1:


Basically, to make your app liquid (or responsive). Follow the following steps:

  1. Set the stage align and scale modes:

    stage.scaleMode = StageScaleMode.NO_SCALE;
    stage.align     = StageAlign.TOP_LEFT;
    
  2. Listen for resize events on the stage:

    stage.addEventListener(Event.RESIZE, stageResizeHandler);
    
    function stageResizeHandler(e:Event):void {
        stage.stageWidth; //how big the width is
        stage.stageHeight; //how big the height is.
    
        //so if you had a box, and you wanted it centered on the screen:
        box.x = (stage.stageWidth - box.width) * .5;
        box.y = (stage.stageHeight - box.height) * .5;
    
        //draw a background
        graphics.clear();
        graphics.beginFill(0xFF0000);
        graphics.drawRect(0,0,stage.stageWidth, stage.stageHeight);
        graphics.endFill();
    }
    

If, you just want to know the physical size of the display, you can do so in the Capabilities class:

Capabilities.screenResolutionX;
Capabilities.screenResolutionY;

OR

stage.fullScreenWidth;
stage.fullScreenHeight;

This usually doesn't include any tool bars /notification bars though.

If you just want your content scaled, then set the scale mode to whatever you'd like:

stage.scaleMode = StageScaleMode.NO_BORDER; 
//this will zoom in your app until it fills the whole screen, though it may crop it a bit if needed.

To see other scaling modes, look here



来源:https://stackoverflow.com/questions/28092972/how-to-determine-and-set-screen-size-at-run-time-using-action-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!