Reputation: 24069
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
Reputation: 467
Set the stage scale mode to "no border":
import flash.display.StageScaleMode;
stage.scaleMode = StageScaleMode.NO_BORDER;
Upvotes: 0
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
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
Reputation: 38867
Check the Screen object for how to do that:
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