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
Contributor
friedit
Posts: 32
Registered: ‎12-08-2010
My Device: Not Specified
Accepted Solution

StageOrientation - not working correctly

[ Edited ]

I'm trying to support the StageOrientation Event but without real success so far. 

 

Here is what I'm doing (basically I copied the HelloWorld code):

 

 

...

stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, onOrientation);

....

switch (stage.deviceOrientation)
{
   case StageOrientation.ROTATED_LEFT:
   case StageOrientation.ROTATED_RIGHT:
   // portrait
   trace("portrait");
   break;

   default:
   // landscape
   trace("landscape");
   break;
}

 

Now the problem is that my output always says "landscape" - and the simulator looks kind of messed up. My "main" components all have x and y set to 0 - so they should appear in the top left corner right?

 

Blackberry Playbook-2011-01-16-12-47-25.png

 

I also added the following lines:

 

 

stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

 

Any ideas?

 

Please use plain text.
Developer
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)
My Carrier: Mobile Vikings

Re: StageOrientation - not working correctly

First of all, add a break statement to your first case. Always add a break to each case, including the default. It's not always necessary, but I like coding with style.

 

Second, the Hello World example is not perfect at the moment. Try this instead:

 

 

private function onOrientationChange(event:StageOrientationEvent):void{
switch (event.afterOrientation)
{
   case StageOrientation.ROTATED_LEFT:
   case StageOrientation.ROTATED_RIGHT:
   // portrait
   trace("portrait");
   break;

   default:
   // landscape
   trace("landscape");
   break;
}
}

 

 

 

 

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Please use plain text.
Contributor
friedit
Posts: 32
Registered: ‎12-08-2010
My Device: Not Specified

Re: StageOrientation - not working correctly

Ok so I get the correct values in the event.afterOrientation property. But what about application startup? My stage.deviceOrientation is always "unkown". Do I have to check if stageWidth > stageHeight?

 

Also: why do I see the simulator home screen after rotating my device (part of it - see the attached screenshot)? Is this a bug? Am I doing something wrong?

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: StageOrientation - not working correctly

[ Edited ]

Other recent threads have addressed both of your questions.  Please use the search feature and/or monitor recent discussions.

 

The stage.deviceOrientation is always unknown right now, and we don't know why.  Use the deprecated stage.orientation instead, until it's fixed.

 

The issue with rotation and the minimized app is a known issue, presumably to be fixed in the next release.  For now, the workaround is to swipe up to show the icons, then just click on the minimized app to restore it in the new orientation.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Contributor
friedit
Posts: 32
Registered: ‎12-08-2010
My Device: Not Specified

Re: StageOrientation - not working correctly

Thank you.

Please use plain text.