Skip to main content
Inspiring
April 26, 2012
Question

Orientation strategy for mobile. Best practice?

  • April 26, 2012
  • 12 replies
  • 1706 views

Hi all.

What's the best way to handle orientation changes on a mobile device when you have several child movies loaded in the background?

I'm thinking:

1. Each child movie have it's own listener for an orientation change. (calls function to adjust graphics as needed so they are ready when the movie is added to stage)

or

2. One primary listener on the main stage which the child movies respond to.

Thoughts? Am I way off-base on this?

Thanks!

JP

PS. Don't think this matters, but just in case, the app is for iOS only.

This topic has been closed for replies.

12 replies

sinious
Legend
April 26, 2012

I dispatch an event from my main and have my children listen and adjust accordingly.

Of course you can always simply use Flex with some simple layout rules and constraints and let Flex do the work for you. Not every complex view is capable of that automation but I tend to stray from making any single view too complex anyhow.

gtrAuthor
Inspiring
April 26, 2012

Thanks, that makes sense. Only, despite my best Googling, I can't find a clear and concise description on how to get the child to listen to the parent. (I understand how to achieve the opposite) What's the simplest way to do this?

Colin Holgate
Inspiring
April 26, 2012

It can get complicated it you want to send an event with data attached, so it could be that the simpler approach would be to have two listeners in each child. Something like this, in each child that needs to rearrange things:

stage.addEventListener("go portrait",goportrait);

stage.addEventListener("go landscape",golandscape);

function goportrait(e:Event){

//do what this child needs when going to portrait

}

function golandscape(e:Event){

//do what this child needs when going to landscape

}

Then in the orientation listener on the stage you would do:

dispatchEvent(new Event("goportrait"));

or:

dispatchEvent(new Event("golandscape"));

You'll read in some places about how it's bad practice to use strings like that, and that you should set up constants with the strings in them. But, using strings is quick and easy, and has no drawbacks at runtime.