stage.stageWidth or stage.fullScreenWidth

Copy link to clipboard
Copied
When developing a multiscreen game or app, developers need to read device's screen size to correctly rescale and reorganise screen elements.
I have been always using stage.fullScreenWidth and stage.fullScreenHeight instead of stage.stageWidth and stageHeight as I heard from other developers that the returned values may be incorrect on some devices. But when I tested my app on Motorola Xoom which has Android 3.0 I noticed that a bottom bar that comes from operating system with Home / Back buttons covers my app (Motorola Xoom doesn't have hardware buttons so they are available on the screen). So AIR returns the full height value, including that bottom bar, what causes my app to be behind it. There are some buttons in the app that could not be reached because of that.
I have tested my app on few Android devices available to me against stage.stageWidth and stageHeight and I got correct values. Can anybody confirm if there are still issues on any devices including iOS? Maybe that was only a problem with AIR 2.0 and 2.5?

Copy link to clipboard
Copied
Just tested on iPhone and noticed that it returns original stage size rather than the actual.
I use
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
and I wait for Event.RESIZE before reading these values...
Copy link to clipboard
Copied
create a timer and read your stage values frequently. Or test with the Orientation event.
Copy link to clipboard
Copied
Hi,
This is a known issue. Like you mentioned, you should wait for RESIZE event before reading these values.
Thanks,
Sanika

Copy link to clipboard
Copied
I wonder if this is a bug and if this is going to be fixed in AIR 2.7? Since stage.fullScreenHeight always returns correct values on iPhone and Android (unlike stage.stageHeight), is there any way of checking what is the height of the Android Honeycomb screen without the bottom system bar? The idea was that I wanted to create truly cross-platform and multi-screen game, where one code would work well on iOS and Android. It works except that small annoying thing... Probably I could detect if the platform is Android and use stage.stageHeight and fullScreenHeight in iOS... but this is not the ideal solution.
Copy link to clipboard
Copied
I would hope that this is stuff coming soon and in the Screen class. On a side note, try using Screen.mainScreen.visibleBounds (not that it works in this case) instead of stage.fullScreenWidth. it is supposed to take account for systemBars.
Copy link to clipboard
Copied
These sizing issues can be very frustrating, especially as behavior is not the same across OSes and devices. This is kind of critical stuff: you would think Adobe would have nailed this some time ago.
A lot of it is adapted from http://sierakowski.eu/list-of-tips/82-starting-with-air-for-android-and-ios-building-one-app-for-bot..., with some enhancements on my part to address the issue raised by sigman.pl, in this thread.
Please, anyone, feel free to correct me if you feel I am going about this the wrong way.
Here is what I do:
private static var _resizeEventFiredOnceAlready:Boolean;
private static const _screenBounds:Rectangle = Screen.mainScreen.visibleBounds;
private var _stageWidth:Number; // Don't get confused: for our use, we mean the SHORTEST visible screen length for the app, irrespective of device orientation. Think of the app being in portrait mode (unlike in Sierakowski's blog)
private var _stageHeight:Number; // LONGEST visible screen length for the app.
public function MyDocClass():void
{
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(evt:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage); // remove this handler
// Below: we only do this once, when the app starts, since another one of this may be instanced later, possibly.
if (!_resizeEventFiredOnceAlready)
{
// Below: we don't want to add (and build) our graphic assets to (based on)
// a stretched stage.
// Rather, we want to build them at the right size, which means we will need
// to know the device screen size in a moment...
stage.align = StageAlign.TOP_LEFT;
// Above: if there is a top status bar, top_left is nevertheless right below it, so we're good...
stage.scaleMode = StageScaleMode.NO_SCALE;
// Above: needs to be set to no_scale, otherwise the resive event, below, won't fire when the app window changes its
// its width or height. That's a how the RESIZE event is supposed to work.
// The default, otherwise, is "SHOW_ALL", which stretches the stage to fit within the window, but does not theorically
// fire the resize event, though it does on iOS ( but not on Android, which is the correct behavior ) *
// * I wished Adobe would fix these inconsistencies...
stage.addEventListener(Event.RESIZE, onResize);
}
else
initThis();
}
private function onResize(e:Event):void
{
stage.removeEventListener(Event.RESIZE, onResize); // remove this handler
_resizeEventFiredOnceAlready = true;
// Determine screen size so that we can properly construct our UI...
//
// The problem with fullScreenWidth/Height is that it gives the entire
// screen dimension, including the area occupied by optional status bars
// (in cases where user set <fullScreen>false</fullScreen>, in the app manifest)
// as well as the non-optional (so I read in this thread from sigman.pl) virtual Android buttons bar,
// on some devices (ex: Xoom w/ Android 3.0).
//
// These status and buttons bars have the potential of causing important UI widgets
// to be partially hidden, so we need to size our app so that it fits nicely within
// the visible area of the screen: hence the use of Screen.mainScreen.visibleBounds.
//
// However, when debugging the app on a computer (CTRL+Enter in Flash CS5),
// Screen.visibleBounds returns the area of the desktop, not the area within the flash window,
// so that's annoying (note: Screen.screens doesn't work as of this writing *). Also, there is no guarantee that in the
// future,mobile OSes might not be able to start apps in a 'minimized' mode (like a computer),
// so we will use Math.min to address both issues, below.
// * Another important unfinished loose end from Adobe
//
// Note: stage.stageWidth/Height would have returned the stage dimensions as was set in CS5,
// regardless of what scaleMode is set at ( scaleMode only affects what the stage looks like,
// stretched or not, on the device, but does not affect the values returned by stageWidth/Height ).
_stageWidth = Math.min( stage.fullScreenWidth, _screenBounds.width );
_stageHeight = Math.min( stage.fullScreenHeight, _screenBounds.height );
// Above: fullScreenWidth and _screenBounds.width always refer to the same side of the screen,
// on any OS and device AFIK, so we're comparing apples to apples.
// Apparently, according to Sierakowski's blog (see link above), stage.fullScreenWidth isn't consistent in always giving the
// same (shortest screen length), when the device is started in landscape mode between iOS and Android *.
// Anyway, let's make sure we always get the shortest screen length:
// * Another Adobe loose end, though I believe this has been fixed in 3.1 (maybe even earlier).
var temp:Number = _stageWidth;
_stageWidth = Math.min( _stageWidth, _stageHeight );
_stageHeight = Math.max( temp, _stageHeight );
// Above: now _stageWidth is always the shortest screen length / and _stageHeight the longest one, irrespective
// of if we started the app in landscape mode or not. We could now swap the 2 at this point, based on device orientation,
// but at least we know what is what.
// Rest of your code
initThis();
}
Note:
My personal preference is to always have my apps run in fullscreenMode = true / aspectRatio = portrait / autoOrients = false, only. If there is a need to redraw/resize stuff based on a change in orientation, then a handler should be able to 'fake' it, rather than actually modifying the stage.
The stage is the stage, let's not f*** with it! It's hard enough as it is...
Copy link to clipboard
Copied
It worked! It worked fantastically. I abandoned stage.fullScreenHeight, stage.stageHeight, and Capabilities.screenResolutionY. because these all come close but if the Android has Virtual buttons my bottom navigation was covered and if the device didn't have virtual button but physical buttons (i.e. most phones. Then the bottom navigation was too high and did not rest on the bottom of the screen.
Thank you AsterLUXman for posting this. Saved a few times pounding my head against the wall.
Copy link to clipboard
Copied
IMPORTANT - BUG IN ABOVE CODE (AsterLUXman).
Not sure if something has changed since this post was written. I am using AIR 13 on iPhone5 (iOS7) and this assumption is not correct:
_stageWidth = Math.min( stage.fullScreenWidth, _screenBounds.width );
_stageHeight = Math.min( stage.fullScreenHeight, _screenBounds.height );
// Above: fullScreenWidth and _screenBounds.width always refer to the same side of the screen,
// on any OS and device AFIK, so we're comparing apples to apples.
In my situation:
- Screen.mainScreen.visibleBounds does NOT change with orientation change
- However, stage.fullScreenWidth and stage.fullScreenHeight swap places during orientation change
Here is my code. I call it once when the game is created/initialised, and then in the onResize event:
var minBound : Number = Math.min( Screen.mainScreen.visibleBounds.width, Screen.mainScreen.visibleBounds.height );
var maxBound : Number = Math.max( Screen.mainScreen.visibleBounds.width, Screen.mainScreen.visibleBounds.height );
if (stage.fullScreenWidth > stage.fullScreenHeight) {
// Landscape
screenWidth = Math.min( stage.fullScreenWidth, maxBound );
screenHeight = Math.min( stage.fullScreenHeight, minBound );
}
else {
// Portrait
screenWidth = Math.min( stage.fullScreenWidth, minBound );
screenHeight = Math.min( stage.fullScreenHeight, maxBound );
}
Note: Unlike the code sample given by AsterLUXman, the above code doesn't swap the dimensions to always keep them in portrait. If you always want the dimensions in portrait mode, use:
var minBound : Number = Math.min( Screen.mainScreen.visibleBounds.width, Screen.mainScreen.visibleBounds.height );
var maxBound : Number = Math.max( Screen.mainScreen.visibleBounds.width, Screen.mainScreen.visibleBounds.height );
if (stage.fullScreenWidth > stage.fullScreenHeight) {
// Landscape. Note: swaps dimensions to always give them in portrait mode
screenHeight = Math.min( stage.fullScreenWidth, maxBound );
screenWidth = Math.min( stage.fullScreenHeight, minBound );
}
else {
// Portrait
screenWidth = Math.min( stage.fullScreenWidth, minBound );
screenHeight = Math.min( stage.fullScreenHeight, maxBound );
}
Copy link to clipboard
Copied
I don’t know if I’ve heard of visibleBounds, but if you are using noscale as the scale mode, the stage ought to be the same as the device screen size. You can use:
screenwidth:int = Math.max(Capabilities.screenResolutionX,Capabilities.screenResolutionY);
screenheight:int = Math.min(Capabilities.screenResolutionX,Capabilities.screenResolutionY);
for landscape, or:
screenwidth:int = Math.min(Capabilities.screenResolutionX,Capabilities.screenResolutionY);
screenheight:int = Math.max(Capabilities.screenResolutionX,Capabilities.screenResolutionY);
for portrait.
Copy link to clipboard
Copied
Reading the original problem that this post is addressing, (and notes from AsterLUXman)
- Using visibleBounds allows for status bars on Android that screenResolutionX does not allow for
- Using stage.fullScreenWidth allows for running on PC/web where screenResolutionX reports the entire screen, not just the stage
Copy link to clipboard
Copied
Good tips, though Android doesn’t support web SWF anymore, does it?
The other thing to ask is if the code waited for a resize event?
Copy link to clipboard
Copied
I don't think Android supports web swf anymore, but this regards multi-platform development. My code is designed to run on iOS, Android and Facebook with very minimal conditional compilation. In this case, visibleBounds works for the Facebook version of my game, and using the comparison between fullScreenWidth and visibleBounds takes care of status bars and the like on Android that obscure part of the stage.
And, yup, as stated, code needs to be called in constructor and onResize
Copy link to clipboard
Copied
Hi Pea,
Thank you for pointing out this bug. I haven't looked into this issue for a long while, so I am a little lost even re-reading the thread.
I remember modifying my code sample above, a while back, but didn't follow through and update the code in this thread at the time, unfortunately.
In case this might be useful to you, here is what I use these days -- I haven't had any problems with it so far.
I basically made a 'Stage Monitor' class, which I add to the stage right away in my app's constructor. I also pass the main init function as a callback, which gets called as soon as the stage dimensions are known.
The stage width and height get stored in static variables, so all my other classes can point to SM.stageWidth, for example, without the instance having been added to the stage ( if it's a display object ) or referencing the stage in some other way.
package com.blah.common { import flash.system.System; import flash.system.Capabilities; import flash.display.Sprite; import flash.display.Stage; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; CONFIG::AIR_APPLICATION { import flash.display.Screen; import flash.events.StageOrientationEvent; } import flash.geom.Rectangle; import flash.geom.Point; public final class SM extends Sprite // SM stands for 'Stage Monitor' ( we use a short word so all we will have to type, for ex, is: SM.stageWidth ) { public static const SCREEN_PPI:Number = Capabilities.screenDPI; CONFIG::AIR_APPLICATION { public static const SCREEN_BOUNDS:Rectangle = Screen.mainScreen.visibleBounds; } private static var _stage:Stage; private static var _stageScaleMode:String; private static var _startupAspect:String; // only used in AIR apps private static var _stageResizedOnceAlready:Boolean; private static var _forceStageWidth:Number; private static var _forceStageHeight:Number; private static var _minStageWidth:Number; private static var _minStageHeight:Number; private static var _forceWidthToHeightRatio:Number; // height stays 100% private static var _forceHeightToWidthRatio:Number; // width stays 100% -- use one or the other private static var _visibleScreenLengthShortest:Number; private static var _visibleScreenLengthLongest:Number; private static var _stageWidth:Number; // orientation dependent private static var _stageHeight:Number; // orientation dependent private static var _stageWidth_d2:Number; private static var _stageHeight_d2:Number; private static var _stageCenter:Point; private static var _stageRect:Rectangle; private static var _stageWtoH:Number; private static var _stageHtoW:Number; private static var _ui_scale_800:Number; private static var _ui_scale_480:Number; private static var _ui_scale_480_width:Number; private var _stageInitedCallback:Function; // NOT static. May vary from instance to instance of this. private var _orientationChangeCallback:Function; // NOT static. May vary from instance to instance of this. public function SM( stageInitedCallback:Function = null , orientationChangeCallback:Function = null , stageScaleMode:String = StageScaleMode.NO_SCALE , startupAspect:String = "portrait" , forceWidthToHeightRatio:Number = NaN // height stays 100% , forceHeightToWidthRatio:Number = NaN // width stays 100% -- use one or the other , minStageWidth:Number = NaN , minStageHeight:Number = NaN , forceStageWidth:Number = NaN , forceStageHeight:Number = NaN ):void { // USAGE: instance with stageInitedCallback set to the 'added to stage' main init function of the container, // and add this to the stage in the constructor. // // Note: this will remove itself from the display list automatically. mouseEnabled = false; mouseChildren = false; visible = false; _stageInitedCallback = stageInitedCallback; _orientationChangeCallback = orientationChangeCallback; _stageScaleMode = stageScaleMode; _startupAspect = startupAspect; // only used in AIR apps _forceWidthToHeightRatio = forceWidthToHeightRatio; _forceHeightToWidthRatio = forceHeightToWidthRatio; _minStageWidth = minStageWidth; _minStageHeight = minStageHeight; _forceStageWidth = forceStageWidth; _forceStageHeight = forceStageHeight; addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true); } private function onAddedToStage( evt:Event ):void { removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false); // remove this (run once only) // Below: if there is no _stage, this means onAddedToStage() hasn't run ONCE yet // ( in other words: this is the first instance of this, so far). if (!_stage) { _stage = stage; // cache stage since we will remove this from the display list in finish() // Below: we don't want to add (and build) our graphic assets to (based on) // a stretched stage. Rather, we want to build them at the right size, which means we will need // to know the device screen size in a moment... if (_stageScaleMode == StageScaleMode.NO_SCALE ) _stage.align = StageAlign.TOP_LEFT; // Above: if there is a top status bar, top_left is nevertheless right below it, so we're good... _stage.scaleMode = _stageScaleMode; // StageScaleMode.NO_SCALE; // Above: needs to be set to no_scale, otherwise the resive event, below, won't fire when // the app window changes its width or height. That's a how the RESIZE event is supposed to work ('Essential ActionScript 3.0', p.207) // The default, otherwise, is "SHOW_ALL", which stretches the stage to fit within the window, but does not theorically // fire the resize event, though it does on iOS ( but not on Android, which is how it's supposed to work ) * // * I wished Adobe would fix these inconsistencies... CONFIG::AIR_APPLICATION { _stage.addEventListener( Event.RESIZE, onStageResized, false, 0, true ); // Let's keep track of orientation changes also, if autoOrients is true if ( (Stage.supportsOrientationChange) && (_stage.autoOrients) ) _stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, onStageOrientationChangeStatic, false, 1, true); // Above: onStageOrientationChangeStatic() is the static version of the function which runs only once per event // ( even if there are several instances this, bc listener points to the same--static--function ) } } else { CONFIG::AIR_APPLICATION { if (_stageResizedOnceAlready) // let's call _stageInitedCallback right away finish(); else // wait for it _stage.addEventListener( Event.RESIZE, onStageResized, false, 0, true ); } } CONFIG::AIR_APPLICATION_NO { // No resize triggered right-away on desktop ( unless we change the size of the browser ) so we need to go right into it initStageDims(); } } private function onStageResized( evt:Event ):void { _stage.removeEventListener(Event.RESIZE, onStageResized, false); // remove this (runs once) initStageDims(); } private function initStageDims():void { if (!_stageResizedOnceAlready) { initVisibleScreenDimensions(); var isPortrait:Boolean = Boolean( _startupAspect == "portrait" ); updateStageDimensions( isPortrait ); _stageResizedOnceAlready = true; } finish(); } private function finish():void { if (_stageInitedCallback != null) _stageInitedCallback(); CONFIG::AIR_APPLICATION { // Let's keep track of orientation changes also, if autoOrients is true AND _orientationChangeCallback is defined if ( (Stage.supportsOrientationChange) && (_stage.autoOrients) && (_orientationChangeCallback != null) ) _stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, onStageOrientationChange, false, 0, false); // Above: // onStageOrientationChange() is the non-static version so it runs once per event, PER instance of this // (since listener points to a 'different' function belonging to each instance of this) // weakReference is false, bc we want to keep this handler going, even if this is marked for sweep by the garbage collector // For ex: if this is removed from the display list and the parent container has no reference to it, as in: addChild( new SM( initFunc ) ) } // remove this from the display list (not needed anymore, since we know what the stage is) if (parent) // logically, there should be at this point, but doesn't hurt... parent.removeChild( this ); } CONFIG::AIR_APPLICATION { private static function onStageOrientationChangeStatic( evt:StageOrientationEvent ):void // static version runs only once per event ( even if there are several instances this, bc listener points to the same--static--function ) { var isPortrait:Boolean = Boolean( _stage.stageWidth < _stage.stageHeight ); updateStageDimensions( isPortrait ); } private function onStageOrientationChange( evt:StageOrientationEvent ):void // not a static function bc _orientationChangeCallback is not static. This runs once per event, PER instance of this. { if (_orientationChangeCallback != null) _orientationChangeCallback(); } } private static function initVisibleScreenDimensions():void { // Determine screen size so that we can properly construct our UI... // // The problem with fullScreenWidth/Height is that it gives the entire // screen dimension, including the area occupied by optional status bars // (in cases where user set fullScreen = false, in the app manifest) // as well as the non-optional (so I read on an Adobe forum thread from sigman.pl) // virtual Android buttons bar, on some devices (ex: Xoom w/ Android 3.0). // // These status and buttons bars have the potential of causing important UI widgets // to be partially hidden, so we need to size our app so that it fits nicely within // the visible area of the screen: hence the use of Screen.mainScreen.visibleBounds. // // However, when debugging the app on a computer (CTRL+Enter in Flash CS5), // Screen.visibleBounds returns the area of the desktop, not the area within the flash window, // so that's annoying (also: Screen.screens doesn't work at this point). Also, there is no // guarantee that in the future,mobile OSes might not be able to start apps in a 'minimized' // mode (like a computer), so we will use Math.min to address both issues. // // Note: // * IF stage.scaleMode != NO_SCALE, stage.stageWidth/Height returns the stage dimensions // as was set in CS5 // * IF stage.scaleMode == NO_SCALE, accroding to the AS3 reference, stage.stageWidth/Height // returns stage ( not original, from the fla ) dimensions...BUT: // According to Sigman.pl, on iPhone, it appears that stageWidth/stageHeight, even after // the first RESIZE event, still gives the original ( from the fla ) stage dimensions. // Note: maybe other resize events get generated that later set it to the right size? // CONFIG::AIR_APPLICATION { // Apparently, according to Sierakowski's blog (http://sierakowski.eu/list-of-tips/82-starting-with-air-for-android-and-ios-building-one-app-for-bot...), // stage.fullScreenWidth isn't consistent in always giving the same side (shortest screen length in portrait), // when the device is started in landscape mode between iOS and Android. // // So, let's use min/max to identify which one is shortest/longest in all cases: _visibleScreenLengthShortest = Math.min( _stage.fullScreenWidth, _stage.fullScreenHeight ); //, SCREEN_BOUNDS.width, SCREEN_BOUNDS.height ); _visibleScreenLengthLongest = Math.max( _stage.fullScreenWidth, _stage.fullScreenHeight ); //, SCREEN_BOUNDS.width, SCREEN_BOUNDS.height ); } CONFIG::AIR_APPLICATION_NO { _visibleScreenLengthShortest = Math.min( _stage.stageWidth, _stage.stageHeight ); _visibleScreenLengthLongest = Math.max( _stage.stageWidth, _stage.stageHeight ); } } public static function updateStageDimensions( isPortrait:Boolean = true ):void { // isPortrait only is used for AIR applications CONFIG::AIR_APPLICATION { _stageWidth = isPortrait ? _visibleScreenLengthShortest : _visibleScreenLengthLongest; _stageHeight = isPortrait ? _visibleScreenLengthLongest : _visibleScreenLengthShortest; } CONFIG::AIR_APPLICATION_NO { _stageWidth = _stage.stageWidth; _stageHeight = _stage.stageHeight; } if ( !isNaN( _minStageWidth ) ) _stageWidth = Math.max( _minStageWidth, _stageWidth ); if ( !isNaN( _minStageHeight ) ) _stageHeight = Math.max( _minStageHeight, _stageHeight ); if ( !isNaN( _forceWidthToHeightRatio ) ) _stageWidth = _stageHeight * _forceWidthToHeightRatio; else if ( !isNaN( _forceHeightToWidthRatio ) ) _stageHeight = _stageWidth * _forceHeightToWidthRatio; // About: _forceStageWidth / Height // // This class ( SM )' main purpose is to basically detect the stage dimensions on the first resize, and then fire the // supplied "stageInitedCallback", so that the app graphic assets can be built to fit the screen. // The SM class secondary purpose is also to provide a way for numerous other classes ( that are not necessarily // Display Objects themsleves, and hence don't have a stage attribute ) to access the stage and its width/height. // // One problem, on the desktop, is that the stage width/height represent the entire area of the desktop, not // just the inside of the browser window. On a mutiple-monitor desktop, that area can be very large, esp. if one of the // monitors is in portrait orientation. So, for this particular case, we may wish to specify a specific stage // width/height for the purpose of initialization of graphic assets. This is our standard stage width/height, we build // our assets based on, regardless of what the stage says. if ( !isNaN( _forceStageWidth ) ) _stageWidth = _forceStageWidth; if ( !isNaN( _forceStageHeight ) ) _stageHeight = _forceStageHeight; _stageWidth_d2 = _stageWidth * 0.5; _stageHeight_d2 = _stageHeight * 0.5; _stageRect = new Rectangle(0, 0, _stageWidth, _stageHeight); _stageCenter = new Point(_stageWidth_d2, _stageHeight_d2); _stageWtoH = _stageWidth / _stageHeight; _stageHtoW = _stageHeight / _stageWidth; _ui_scale_800 = _stageHeight / 800; // 800 comes from the fact that the original fla's stage was 800 pixels tall, so this is used to reposition and rescale assets which were designed to fit this size originally (note: the stage dimensions vary on Android devices) _ui_scale_480 = _stageHeight / 480; _ui_scale_480_width = _stageWidth / 480; } public static function get stageWidth():Number { return _stageWidth; } public static function get stageHeight():Number { return _stageHeight; } public static function get stageWidth_d2():Number { return _stageWidth_d2; } public static function get stageHeight_d2():Number { return _stageHeight_d2; } public static function get stageRect():Rectangle { return _stageRect.clone(); } public static function get stageCenter():Point { return _stageCenter.clone(); } public static function getStage():Stage { return _stage; } public static function get UI_SCALE_800():Number { return _ui_scale_800; } public static function get UI_SCALE_480():Number { return _ui_scale_480; } public static function get UI_SCALE_480_WIDTH():Number { return _ui_scale_480_width; } public static function get stageWtoH():Number { return _stageWtoH; } public static function get stageHtoW():Number { return _stageHtoW; } } // End of: class } // End of: package |
Copy link to clipboard
Copied
AsterLUXman, thanks for the post, it looks like the solution I need, but I can't get it working.
I've two questions:
1) I can't get the screen sizes, they return NaN, I think its due the initialization. How do you initialize the class in your main app?
2) The CONFIG::AIR APPLICATION part throws an error, I commented this part out because i'm compiling for air, but is this correct?
Thanks for your help.
Jeroen
Copy link to clipboard
Copied
Hi Jeroen,
1) to initiliaze the SM class, you would do:
public function MyAppConstrutor():void
{
addChild( new SM( init ) );
}
init(), being your main intialization function, which will be called by SM once the screen sizes become known on your mobile device.
2) CONFIG::AIR_APPLICATION is a config constant ( same as a preprocessor directive, in other languages ), and is set in "Publish Settings > Advanced Actionscript 3.0 Settings > Config constants" window, in Flash Professional CSx. If you use a different development environment, I am not sure where you would set it. By setting it to true, you are basically indicating that you are compiling an AIR app, as opposed to a flash ( browser ) app. This config constant is not part of AS3, but something I use for my code, to dinstiguish when I can use routines that are available only in Adobe AIR ( as opposed to regular Flash ). I also have another config constant CONFIG::AIR_APPLICATION_NO for code branches that are intended specifically for Flash in the browser.
Copy link to clipboard
Copied
Totally worked! Thanks!
