panthro
panthro

Reputation: 24069

How can I get the screen size in Air?

In AS3 code for Air, how can I get the screen width and height of the mobile device its running on?

Upvotes: 4

Views: 15634

Answers (4)

S At
S At

Reputation: 467

Set the stage scale mode to "no border":

import flash.display.StageScaleMode;

 stage.scaleMode = StageScaleMode.NO_BORDER;

Upvotes: 0

walv
walv

Reputation: 2878

If you use emulators on the desktop, Capabilities will return the resolution of you computer but not of emulated device.
Just simply use stage for this:

trace(stage.fullScreenWidth, stage.fullScreenHeight);

Upvotes: 12

Chunky Chunk
Chunky Chunk

Reputation: 17237

another method, besides chubbard's answer, is to simply use the Capabilities class, which also works outside of AIR:

import flash.system.Capabilities;

var screenWidth:Number = Capabilities.screenResolutionX;
var screenHeight:Number = Capabilities.screenResolutionY;

Upvotes: 4

chubbsondubs
chubbsondubs

Reputation: 38867

Check the Screen object for how to do that:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Screen.html#includeExamplesSummary

You can pretty easily figure out the dimensions of your NativeWindow, then find the screen it's on, and see the bounds by doing this:

var appBounds : Rectangle = stage.nativeWindow.bounds;
var screen : Screen = Screen.getScreensForRectangle( appBounds )[0];
var screenBounds : Rectangle = screen.bounds;

Upvotes: 7

Related Questions