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
apman
Posts: 194
Registered: ‎11-12-2010
My Device: Not Specified

Locking orientation *completely*

I'm working on a game that uses the accelerometer. Tipping the device in all directions is part of the game, so I don't want the UI to turn at all.

 

But if I set the -app.xml to

   <autoOrients>false</autoOrients>
   <aspectRatio>landscape</aspectRatio>

the UI still flips between landscape and landscape-upside-down.

 

I also added a stage.autoOrients = false; for good measure, but it doesn't make any difference.

 

On the DevAlpha I can work around this by making the app pretend it's Portrait and just turning my top-level Sprite, because the DevAlpha doesn't support portrait-upside-down. But on the PlayBook that wouldn't work since it turns four ways.

 

Does anybody know how to force one orientation only, e.g. landscape, volume buttons up ...?

 

 


My app : Get set - Get up!   Get ready for the snooze revolution.

Developer
Torres90
Posts: 102
Registered: ‎01-12-2011
My Device: Blackberry Playbook

Re: Locking orientation *completely*

	stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, handleOrientationChanging);
		
		
		private function handleOrientationChanging(e:StageOrientationEvent):void 
		{
			e.preventDefault();
		}

 Try this code.

Click "like" if my reply helps and click "Accept as Solution" if it solves your problem!

twitter @Twopinstudio
my vendor page https://appworld.blackberry.com/webstore/vendor/7126/?lang=en
Developer
apman
Posts: 194
Registered: ‎11-12-2010
My Device: Not Specified

Re: Locking orientation *completely*

Thanks, that was a good hint - although with the xml set to <autoOrients>false</autoOrients> you don't get any StageOrientationEvents anymore. So I ended up using <autoOrients>true</autoOrients> , rotating my main sprite if stageHeight > stageWidth, and preventing any further changes with your method.

 

It doesn't seem like the 'proper' way to do it, but works ... (I also experimented with stage.setOrientation and stage.setAspectRatio, but couldn't see either of them doing anything at al )

 

(I won't accept this as the 'solution', maybe someone else still knows a better way ...)

 

 


My app : Get set - Get up!   Get ready for the snooze revolution.

Contributor
tylorpin
Posts: 39
Registered: ‎06-13-2011
My Device: playbook, torch 9810 and Alpha device!

Re: Locking orientation *completely*

[ Edited ]
 
What do u mean by rotating ur main height when stageHeight>stageWidth? U didn't set the aspectRatio=landscape and further prevent orientation changes?
Developer
apman
Posts: 194
Registered: ‎11-12-2010
My Device: Not Specified

Re: Locking orientation *completely*

[ Edited ]

Sorry, I guess I wasn't very clear about what I did, seeing that my point was that there must be a more straightforward way of doing it ...

 

Here is the only way I've figured out so far:

 

In the -app.xml file I have:

	<!-- <aspectRatio>landscape</aspectRatio>  makes no difference if autoOrients = true -->
	<autoOrients>true</autoOrients>

 My main class then looks like this:

 public static var appRotated:Boolean;
 public static var appWidth:uint;
 public static var appHeight:uint;
 
 public function App()
 {		
    stage.align = StageAlign.TOP_LEFT;
    stage.scaleMode = StageScaleMode.NO_SCALE;
    stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, stopTurning);

    App.appRotated = (stage.stageWidth > stage.stageHeight) ? false : true;
    App.appWidth = (App.appRotated) ? stage.stageHeight : stage.stageWidth;
    App.appHeight = (App.appRotated) ? stage.stageWidth : stage.stageHeight;

    // if the device is currently in portrait mode, turn this whole container around
    rotation = (App.appRotated) ? 90 : 0;
    x = (App.appRotated) ? stage.stageWidth : 0;

    // add the actual UI 
// (Elements within the UI are scaled & layed out based on App.appWidth/App.appHeight.
// App.appRotated is used to adjust accelerometer data for the rotation if needed ) labyrinth = new Labyrinth(); addChild(labyrinth); } private function stopTurning(e:StageOrientationEvent):void { e.preventDefault(); }

 


My app : Get set - Get up!   Get ready for the snooze revolution.

Developer
Torres90
Posts: 102
Registered: ‎01-12-2011
My Device: Blackberry Playbook

Re: Locking orientation *completely*

hmm, i think i can't help u much with your problem, cause as far as i'm concern in landscape mode It'll automatic turn to upside down whenever i try to tilt it.

 

Try ur luck in native forum, because i played the game Shadowgun on the playbook and they did exactly the thing u asked for, and that's coded in union engine.

Click "like" if my reply helps and click "Accept as Solution" if it solves your problem!

twitter @Twopinstudio
my vendor page https://appworld.blackberry.com/webstore/vendor/7126/?lang=en