Skip to main content
Projectitis
Inspiring
January 22, 2014
Question

iPhone5 stage.stageWidth inconsistancies

  • January 22, 2014
  • 1 reply
  • 427 views

Hi all,

I've never had this problem before, and been developing AIR apps for mobile for some time (with this exact same code).  It may be due to AIR4.0 BETA, which I am using for this project.

On iPhone 5, the following code will tell me that the stage size is 960 x 1524:

// Scaling and positioning

stage.scaleMode = StageScaleMode.NO_SCALE;

stage.align = StageAlign.TOP_LEFT;

stage.quality = StageQuality.HIGH;

// Screen size

screenWidth = stage.stageWidth;

screenHeight = stage.stageHeight;

However, after a rotation event, the stageWidth/stageHeight is reported as 640 x 1136, which is what I've always had in the past.  This is also the value I would expect from the code above (which is run directly on start-up of the app).

I can't ask my users to rotate their phone every time they start the app, so does anyone know a way to get the correct stageWidth and stageHeight from the start?

Cheers,

Peter

This topic has been closed for replies.

1 reply

Colin Holgate
Inspiring
January 22, 2014

You would normally trust the values after a resize event. But as you’re using no scale you could use the device resolution as your stage size, which is:

Capabilities.screenResolutionX;

Capabilities.screenResolutionY;

Projectitis
Inspiring
January 23, 2014

Thanks Colin - all well and good, but I don't really want different code branches for different platforms if I can help it (i.e. on PC screenResolutionX would not be correct).

I found what it was - on launch and during the preloading stage, my original code waits for 200ms after a resize event just in case another resize happens.  On iOS the resize event is fired multiple times on start-up (usually 2 times), the first time the stageWIdth and stageHeight are incorrect. Sometimes on Android multiple resize events are also fired, or sometimes even none, depending on the situation, so my code has to handle all cases!  Therefore I always wait until I am not getting any more resize events for at least 200ms before I conclude that the screen size is being reported correctly. 

I had mistakenly removed that 'wait' code from my latest project, and preloading was happening faster than the resize events.