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
New Developer
Posts: 129
Registered: ‎11-21-2012
My Device: Z10
My Carrier: -

How to get landscape orientation?

[ Edited ]

Hello guys! Does anyone know how to get which side of the device the landscape is displaying?

 

I already know which side the device is rotated with "stage.deviceOrientation" but, in landscape mode, the device orientation can be "default" or "Upside Down" too and the landscape could be displaying either from left or right.

 

I also got a the Air window with "IowWindow.getAirWindow()" and ask its rotation and it returns 90 or 270, but it depends on the initial state of the app and never changes again although I rotate the device.

 

Any ideas?

Thank you!

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: How to get landscape orientation?

Look at the event StageOrientationEvent. Listen to ORIENTTION_CHANGE (or ORIENTATION_CHANGING) and the event.afterOrientation should provide values like rotatedRight, rotatedLeft, upsideDown and default.
New Developer
Posts: 129
Registered: ‎11-21-2012
My Device: Z10
My Carrier: -

Re: How to get landscape orientation?

Thank you for answering!

 

I added the following code when initializing my Main class:

 

stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, GetOrientation, false, 0, true);

 

However, it seems that the event is not dispatched because the code in the "GetOrientation" function is never executed.

 

What could I be doing wrong?

 

Thank you!

 

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: How to get landscape orientation?

Maybe nothing. I had it in my code, but I dont utilize it (never really needed it). It might be a Flash thing, but that does not mean BB10 supports it. Are you adding the listener after the stage has been completed (added to stage)?

Back to the original question. Why do you care which orientation occurs? You can just update the UI based on an update displaylist call of a UIComponent.
New Developer
Posts: 129
Registered: ‎11-21-2012
My Device: Z10
My Carrier: -

Re: How to get landscape orientation?

Yeah, I have this:

 

public function Main():void
{
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
}
        
private function init(event:Event = null):void
{
         removeEventListener(Event.ADDED_TO_STAGE, init);
            
         stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, GetOrientation, false, 0, true);

         ...

}

 

Regarding the reason of my question, it's a little embarrassing. I couldn't get to work the static/dynamic cover tutorial so I put a picture in front of my app everytime the user minimizes it so it gets displayed as a cover. The problem emerges when the user rotates the device and the AIR window changes orientation because the thumbnail displays the picture upside-down.

 

All of my UI is custom, how can I use an update displaylist call of a UIComponent?

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: How to get landscape orientation?

The BB UIComponent has a function that gets called automatically (updateDisplayList) any time the orientation changes. I update the UI there based on the width and height parameters being passed in. Have not experienced upside down issues.
Highlighted
New Developer
Posts: 129
Registered: ‎11-21-2012
My Device: Z10
My Carrier: -

Re: How to get landscape orientation?

[ Edited ]

I declared the element as an Image, subclass of the UIComponent. I tried to alter its align parameters and override the updateDisplayList but the image still rotates when the device changes orientation.

I just want the image to stay always in the top-left corner of the screen even when the user rotates the device. The app is landscape-only and rotates when orientating left or right, that's good, but I want this particular image to stay always on the top-left corner regardless of the device orientation.

Am I approaching the issue in a wrong way?


Thank you for answering!