0

I have an app that is displaying images. It resizes them based on screen rotation, usually setting "picwidth = screen.width", where "picwidth" is an attribute that the width of each picture is bound to.

So I have several functions similar to:

protected function changeOrientation(e:StageOrientationEvent):void
               {
                     picwidth = screen.width;
                     picheight = screen.width*1.467;
               }

I have also tried doing this with the variable of the object itself:

protected function changeOrientation(e:StageOrientationEvent):void
               {
                   img.width = screen.width;
                   img.height = screen.width*1.467;
               }

and in the emulator, these functions work properly. But on the device, "screen.width" always seems to grab the value before the orientation change, giving dimensions that are exactly opposite of what I needed.

NOTE: this does not just occur with images, it happens with Group containers, TextAreas, anything whose dimensions depend on the screen dimensions.

I have tried simply switching the values so it gets the values and assigns them to the opposite variables to account for the delay, and they work on my device then, but they are backwards in the emulator and I am afraid other devices will function as the emulator does, and it will be broken once again.

Is there any good solution to this?

JeffryHouser
  • 39,401
  • 4
  • 38
  • 59
jlehenbauer
  • 599
  • 2
  • 11
  • 33

1 Answers1

1

This problem was fixed by:

change the event listener from:

stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, changeView);

to:

stage.addEventListener(Event.RESIZE, changeView);

and passing an Event instead of a stageOrientationEvent to each of the handler methods.

Worked in every instance I needed. It's kindof a shame that the only thing that StageOrientationEvent.ORIENTATION_CHANGE is designed to do can be outperformed by a more general function..

jlehenbauer
  • 599
  • 2
  • 11
  • 33