Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
steve_web
Posts: 319
Registered: ‎05-07-2009
My Device: BlackBerry Z10, PlayBook, 9900
My Carrier: Telus

Avoiding hardcoding screen sizes in AIR apps

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-10-screen-resolutions/ )

 

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


PlayBook Apps: DataMine, Dots + Boxes, 5 Marbles
BlackBerry SmartPhone Apps: 5 Marbles Soon: **** (D.Z.A), ****Quest, **** Challenge, VaultCracker, DevBrowser, Radial****
Please use plain text.
Developer
Ebscer
Posts: 840
Registered: ‎08-31-2009
My Device: 9530, 9630, 9800, 8530, 9900, 9810, 9930, PlayBook, Dev Alpha
My Carrier: Verizon

Re: Avoiding hardcoding screen sizes in AIR apps

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).


Read my thoughts on BlackBerry Development at news.ebscer.com
Please use plain text.
Developer
steve_web
Posts: 319
Registered: ‎05-07-2009
My Device: BlackBerry Z10, PlayBook, 9900
My Carrier: Telus

Re: Avoiding hardcoding screen sizes in AIR apps

Yeah I could do that... but I must confess I'm also not sure for BB10 phones with a keyboard where the screen is actually a square... is "Landscape" considered to be the phone orientation like the Bold 9900 where the device is longer in the vertical... but the screen is longer in the horizontal... OR is the BB10 devices with a keyboard the opposite... and "Landscape" is when the device is turned 90 degrees... and thus the horizontal length is longer (720+the sideways keyboard). ;-)

PlayBook Apps: DataMine, Dots + Boxes, 5 Marbles
BlackBerry SmartPhone Apps: 5 Marbles Soon: **** (D.Z.A), ****Quest, **** Challenge, VaultCracker, DevBrowser, Radial****
Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Avoiding hardcoding screen sizes in AIR apps

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.

Please use plain text.
Developer
steve_web
Posts: 319
Registered: ‎05-07-2009
My Device: BlackBerry Z10, PlayBook, 9900
My Carrier: Telus

Re: Avoiding hardcoding screen sizes in AIR apps

Thanks jtegen I'll check it out!

PlayBook Apps: DataMine, Dots + Boxes, 5 Marbles
BlackBerry SmartPhone Apps: 5 Marbles Soon: **** (D.Z.A), ****Quest, **** Challenge, VaultCracker, DevBrowser, Radial****
Please use plain text.
BlackBerry Development Advisor (Retired)
dmalik
Posts: 427
Registered: ‎02-22-2012
My Device: BlackBerry Z10, BlackBerry Dev Alpha C, BlackBerry PlayBook
My Carrier: Bell

Re: Avoiding hardcoding screen sizes in AIR apps

Sarah Northway wrote a good article on this topic here - http://www.adobe.com/devnet/air/articles/multiple-screen-sizes.html 

 

Cheers,
Dustin

Follow me on Twitter: @dustinmalik
-----------------------------------------------------------------------------------------------------
Keep up to date on BlackBerry development: http://devblog.blackberry.com/
Please use plain text.