Flex 4.5 Problems with mobile iOS with determining the actual resolution of the screen / scene

I have a pretty big problem. I hope this is due to my own stupidity, not some kind of mistake. I have a code that needs to know screen sizes. I have not found a reliable way to do this. Using the Flash Builder 4.5 product release on iPad 2 and iPhone4 / iPod Touch 4 iOS devices. In general, my application works fine, but I can not determine the screen size and orientation during the start of the program. Let me explain the problems that I'm having:

When you enter the init function called by the ADDED_TO_STAGE event, the values โ€‹โ€‹of stage.stageHeight and stage.stageWidth are 0.

I can request Capabilities.screenResolutionX and Capabilities.screenResolutionY, but they are WRONG. They have initial values โ€‹โ€‹of X and Y, but regardless of orientation. So, for example, I run in landscape mode screenResolutionX contains 768 (or something else) instead of 1024.

I am looking at the stage.width and stage.height values โ€‹โ€‹and they do not have valid values.

I have a function onResize function for EVENT.RESIZE, but it is not called if the application starts from the device when it is already in landscape mode. If I launch the application in portrait mode and then rotate, it causes a call.

So my question is what should I request right at application launch to find out the real width and height of the application. There must be a way to do this, but apparently don't use any of the above methods!

By the way, this is on iOS devices. I canโ€™t say how it works on others. I confirmed these results by printing the results and running them in the debugger.

+6
source share
3 answers

I had previously had problems with stageWidth and stageHeight, not giving proper values โ€‹โ€‹right at startup, an easy way to get around this is to wait a frame or two before checking them.

One option is to delay the initialization of your application, something like this:

private var _startup_delay:int = 10; public function Constructor(){ addEventListener(Event.ENTER_FRAME, handleEnterFrame); } public function handleEnterFrame(e:Event):void{ _startup_delay--; if(_startup_delay <= 0){ init(); removeEventListener(Event.ENTER_FRAME, handleEnterFrame); } } 

Another option is to instead send a fake resize event and let your previous rotation code handle it after downtime:

 public function handleEnterFrame(e:Event):void{ _startup_delay--; if(_startup_delay <= 0){ stage.dispatchEvent(new Event(Event.RESIZE)); removeEventListener(Event.ENTER_FRAME, handleEnterFrame); } } 
+1
source

Short answer:

The easiest way is to use the properties of stage.fullScreenWidth and stage.fullScreenHeight .

They correctly report the screen size for any orientation and any platforms during startup (there is no need to wait for ADDED_TO_STAGE or RESIZE events).

More details:

On Android and Blackberry, AIR reports the same (and correct values) at any time using any of the following properties:

  • stage.stageWidth and stage.stageHeight
  • Screen.mainScreen.bounds.width and Screen.mainScreen.bounds.height
  • stage.fullScreenWidth and stage.fullScreenHeight

On iOS, when launched, three syntaxes give three different results (the following are approximate values โ€‹โ€‹for an application running on iPad2 in landscape mode):

  • stage.stageWidth / Height: default scene size when running swf (500x375)
  • Screen.mainScreen.bounds: physical screen resolution in portrait mode (768x1024)
  • stage.fullScreenWidth / Height: The correct screen resolution in the specified orientation. (1024x768 - correct)

Note that on iOS, the RESIZE event is fired twice when the application is launched, but the values โ€‹โ€‹are only valid a second time (stage.stageWidth == stage.fullScreenWidth).

+4
source

in app start, will

 public function Main() { loaderInfo.addEventListener(Event.COMPLETE, _onComplete_loaderInfo); } private function _onComplete_loaderInfo(__e:Event):void { // I should now have access to stage.stageWidth/stage.stageHeight. } 

work to get screen resolution? I would like to state that I NEVER investigated this, I was just looking for something else and ran into your problem and just commented on Aloud. Now I'm not saying that they will be the correct values, but they should at least NOT be null.

0
source

Source: https://habr.com/ru/post/887231/


All Articles