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: 11
Registered: ‎01-18-2011
My Device: Not Specified
Accepted Solution

Orientation change not right when rotating back

[ Edited ]

Hello all,

 

I just found a problem while trying to listen for orientation changes. I'm using SDK 1.0.1 and testing on a device with OS 1.0.3.1868 installed. I hope I can make myself clear:

 

If I rotate the device 360 degrees in the same direction everything works fine. However, when I change direction things get messy.

 

Say my current orientation is in position 1 and I rotate clockwise to position 2. From position 2, if I rotate counterclockwise back to position 1 an orientation change event is triggered, but it doesn't actually change the orientation. The orientation itself stays in position 2, but it does trigger a change event as evidenced by a screen flash.

 

Now, the device is still showing position 2 but the device itself is physically in position 1. I have to physically rotate it to position 2 and then back again to 1 to see the content according to position 1.

 

[edit]

 In other words, to get this behavior I need to rotate a device twice. First in any direction, and then in the opposite direction.

 

The OS does change to the correct position. The stage registers an ORIENTATION_CHANGE or RESIZE event, but not an actual change as it stays in the same position.

[/edit]

 

I listened the stage for StageOrientationEvent.ORIENTATION_CHANGE and Event.RESIZE with the same results.

 

Am I missing the obvious or is this a bug? I didn't find it in the issue tracker.

 

Code attached.

 

Thanks in advance for any help.

 

Daniel

 

 

package
{
	import flash.display.MovieClip;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;

	import flash.events.Event;
	
	import qnx.ui.text.Label;

	[SWF(backgroundColor = "#FFFFFF", frameRate = "30", width = "1024", height = "600")]
	public class OrientationTest extends MovieClip
	{
		private var label:Label;
	
		public function OrientationTest()
		{
			label = new Label;
			addChild(label);
		
			addEventListener(Event.ADDED_TO_STAGE, ready);
		}
		
		private function ready(e:Event):void
		{
			removeEventListener(e.type, arguments.callee);
			
			stage.align = StageAlign.TOP_LEFT; 
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			stage.addEventListener(Event.RESIZE, notify);
		}
		
		private function notify(e:Event):void
		{
			label.setSize(stage.stageWidth, stage.stageHeight);
			
			label.text = stage.orientation + ": " + stage.stageWidth + "x" + stage.stageHeight;
		}
	}
}

XML descriptor initialWindow:

<initialWindow>
		<content>OrientationTest.swf</content>
		<visible>true</visible>
		<fullScreen>true</fullScreen>
		<resizable>true</resizable>
		<autoOrients>true</autoOrients>
		<renderMode>gpu</renderMode>
</initialWindow>
Contributor
Posts: 11
Registered: ‎03-29-2011
My Device: Playbook and Blackberry Torch
My Carrier: Mobile Application developer

Re: Orientation change not right when rotating back

 

 

in stage orientation event try aligning your labels for the following rotation types.

 

StageOrientation.ROTATED_LEFT, 

StageOrientation.ROTATED_RIGHT etc

Contributor
Posts: 20
Registered: ‎03-22-2011
My Device: playbook and 9800
My Carrier: airtel

Re: Orientation change not right when rotating back

Use this code it is tested and its working fine

<?xml version="1.0" encoding="utf-8"?>
<!--This view contains webview, header and footer. Pages are loaded on webview.
The page to be loaded is determined by comparator.-->
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:components="components.*"
actionBarVisible="false" creationComplete="init()">

<fxSmiley Frustratedcript&gt;
<![CDATA[
import mx.events.ResizeEvent;
private var landscape:Boolean;
/**
* This function is called on creation of view.
* */
private function init():void
{

if (stage.stageHeight == 600 && stage.stageWidth == 1024){ // if we're in landscape at start
landscape = true;
//stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, function (event:Event):void {
// trace(stage.deviceOrientation);
trace ("Land");
switch (stage.deviceOrientation) {
case StageOrientation.DEFAULT:
trace("land default")
landscape = true;
reorient();
break;
case StageOrientation.ROTATED_RIGHT:
trace("land right")
landscape = false;
reorient();
break;
case StageOrientation.ROTATED_LEFT:
trace("land left")
landscape = false;
reorient();
break;
case StageOrientation.UPSIDE_DOWN:
trace("land invert")
landscape = true;
reorient();
break;
case StageOrientation.UNKNOWN:

trace("Unknown.");
break;
}
});

if (stage.stageHeight == 600 && stage.stageWidth == 1024)
{landscape = true;}
else
{landscape = false;}
reorient();
}
else {
trace ("Port");
landscape = false;
//stage.align = StageAlign.BOTTOM_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
//labelHome.x=480;
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, function (event:Event):void {
// trace(stage.deviceOrientation);
switch (stage.deviceOrientation)
{

case StageOrientation.DEFAULT:
trace("Port default")
landscape = true;
reorient();
break;
case StageOrientation.ROTATED_RIGHT:
trace("Port right")
landscape = false;
reorient();
break;
case StageOrientation.ROTATED_LEFT:
trace("Port left")
landscape = false;

reorient();
break;
case StageOrientation.UPSIDE_DOWN:
trace("Port invert")
landscape = true;
reorient();
break;
case StageOrientation.UNKNOWN:
trace("Unknown.");
break;
}
});

if (stage.stageHeight == 600 && stage.stageWidth == 1024)
{landscape = true;}
else
{landscape = false;}
reorient();
}

}


private function reorient(){



if (landscape){
l.x=stage.width/2;
l.y=stage.height/2;
}
else { // if in portrait
if(stage.stageHeight==1024 && stage.stageWidth==600 )
{

l.x=stage.width/2;
l.y=stage.height/2;
}
}

}





]]>
</fxSmiley Frustratedcript&gt;
<s:Label id="l" x="198" y="228" text="orient"/>

</s:View>

If u have any question regarding this u can ask me ,in this i am using StageOrientationEvent.ORIENTATION_CHANGE event ,even we can do orientation using acelerometer event .
New Developer
Posts: 11
Registered: ‎01-18-2011
My Device: Not Specified

Re: Orientation change not right when rotating back

jaimotwani,

 

Thanks for your suggestion, but it doesn't do anything in this context. I'm using an actual device and orientation changes do get fired up no matter what.

 

The issue is when I am rotating something clockwise (or counterclockwise) and decide to rotate back in the opposite direction.

 

 

coll_hupar,

 

Thanks a lot for your code, however, the problem remains for me. Are you testing on a physical device? If so, is it the same OS version as mine (1.0.3.1868)?

 

The OS itself changes to the right  position but the stage reports the previous position as its new position and doesn't actually rotate the screen. But this only happens when changing direction of rotation, and needs at least two rotations in order for this to happen.

New Developer
Posts: 11
Registered: ‎01-18-2011
My Device: Not Specified

Re: Orientation change not right when rotating back

Found the culprit.

 

In the application descriptor xml, the quirk only happens when renderMode is gpu:

 

<renderMode>gpu</renderMode>

 

Changing it to auto or cpu works fine (auto defaults to cpu):

<renderMode>auto</renderMode>

or

<renderMode>cpu</renderMode>

I'm filing this as a bug.

Highlighted
New Developer
Posts: 11
Registered: ‎01-18-2011
My Device: Not Specified

Re: Orientation change not right when rotating back