09-14-2012 09:54 AM
As any "good" developer does... I want to try and avoid hardcoding any screen size information in my AIR based apps to ensure that they can work on the PlayBook (1024x600), the BB10 FullTouch (1280x720), the BB10 w/Keyboard (720x720)... and anything else that may ever come up in the future... (even though RIM has indicated they are constraining themsleves for BB10 to the above dimensions as noted here: http://devblog.blackberry.com/2012/08/blackberry-1
So in order for this to work... I need to ensure:
a.) any default configuration doesn't lock in a size...
b.) I need to be able to programatically read in the device dimensions (and know if I need to "rotate" my view)
For item (a) I've been a bit confused by the opening line I've seen in documentation for your *.as class files that starts like this...
package{
import abc;
...
[SWF(width="1024", height="600", backgroundColor="#000000", frameRate="30")]
public class MyAppName extends Sprite{
...
}
}
Although I'll be honest I haven't even tried... can I drop that metadata line? or can I change the values to variables like ${DeviceWidth}, $DeviceHeight}...? or is there a better option?
For item (b) I need to be able to read in the actual device dimensions.... (width, height) and potentially "know" how to force the rotation.
e.g. for a Game I'm making... it is intended to run in the "Landscape" orientation on the PlayBook (and on a full touch BB10 phone)... and although it really wouldn't matter... I'm guessing I'd prefer the "portrait" orientation for a BB10 keyboard phone (even though the screen resolution would be the same at any orientation.
Am I right to be looking at these values for width and height?
var width:int = qnx.display.DisplayMode.width; var height:int = qnx.display.DisplayMode.height;
and for orientation... this one?
var isPreferred:Boolean = qnx.display.DisplayMode.isPreferred;
Cheers,
Steve
09-14-2012 10:24 AM
If you are looking to force the application into Portriat or Landscape mode, you are best off doing that from the xml file instead of in code.
Also I believe that it is safe to drop the metadata line (but have to admit that I haven't tried it).
09-14-2012 10:27 AM
09-14-2012 07:44 PM
You can drop the meta line and include this in your main constructor:
this.stage.frameRate = 30; this.stage.align = StageAlign.TOP_LEFT; this.stage.scaleMode = StageScaleMode.NO_SCALE;
The stage size is picked up from the device boundary.
In the update display function, you can compare the width and height to determine orientation. Portrait ( w < h ) is "normal" orientation of the device.
09-14-2012 07:47 PM
09-17-2012 11:45 AM
Sarah Northway wrote a good article on this topic here - http://www.adobe.com/devnet/air/articles/multiple-
Cheers,
Dustin