Skip to main content
Participant
Oct 28, 2011 8:58 AM UTC
Question

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

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

This topic is closed to new replies. Start a new post to keep the conversation going.

7 replies

Known Participant
Nov 1, 2011 11:52 AM UTC

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

Translate
Colin Holgate
Inspiring
Nov 1, 2011 2:17 PM UTC

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.

Translate
Oct 30, 2011 7:58 PM UTC

What platform you are talking about?

Translate
holyencnmAuthor
Participant
Oct 31, 2011 7:12 AM UTC

Android

Translate
Oct 31, 2011 11:42 AM UTC

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;

            }

        }

Translate