Skip to main content
Participant
October 28, 2011
Question

How can i get Screen's Width&Height Of Mobile

  • October 28, 2011
  • 2 replies
  • 1561 views

i want to get Screen's width,height .how can i write the code?

This topic has been closed for replies.

2 replies

Known Participant
November 1, 2011

You can get screen width and height from the Capabilities class...

var screenWidth:int = Capabilities.screenResolutionX

var screenHeight = Capabilities.screenResolutionY

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Capabilities.html#screenResolutionX

Colin Holgate
Inspiring
November 1, 2011

I'll test this later, but it would be interesting to see if those numbers refer to the width and height of the device's Default orientation. That could help with the problem where Android tablets think of landscape as being Default, and other devices (including iPad) thinking of portrait as being Default.

October 30, 2011

What platform you are talking about?

holyencnmAuthor
Participant
October 31, 2011

Android

October 31, 2011

There have been some issues with obtaining the accurate screen width and height at startup, and what some of us have done is to implement code which waits a  few seconds before grabbing that info. Something along these lines(you'll have to work this code into your own app):

private var _appHeight;

private var _appwidth;

private var _startup_delay;

//set delay for app startup

_startup_delay = 10;

           

           

//add listener for enter frame

addEventListener(Event.ENTER_FRAME, _handleEnterFrame);  

private function _handleEnterFrame(e:Event):void{

           

         //start at 10 and count down to zero.

         _startup_delay--;

           

            //start the delay

            if(_startup_delay <= 0){

               

                //remove enter frame listener

                removeEventListener(Event.ENTER_FRAME, _handleEnterFrame);

               

               //configure the stage--------------------------------------------------------//

                stage.scaleMode = StageScaleMode.NO_SCALE;

                stage.align = StageAlign.TOP_LEFT;

                stage.quality = "high";

              //grab screen width and height

               _appwidth = stage.stageWidth;

               _appHeight = stage.stageHeight;

            }

        }