January 25, 2010

WindowedApplication reload - position and size problem

If you are reading the post then you are perhaps having trouble with the size and position of your Air application after it is reloaded. This is not a bug, just a gotcha.

The symptoms of the problem are:
The application will reload as a tiny size (approx. 50x50 pixel) The size randomly varies but always small.
The position of the (now tiny) application is often outside the visible area of the screen.

This problem stems from to storing the size and position of the application so it can be repositioned to that users last chosen size and location. In my case I used a local shared object.

The scenario is this: I added event listeners to the WindowedApplication resize and position events and updated the local shared object every time the user repositioned or re-sized the window.

What I failed to realise until later is that when ever the application is closed or minimised it has an animation associated with it. Silly me thought that this was perhaps a operating system handled animation, that Vista OS was animating the application as part of its standard behavior. This was not the case and the animations are actually from the motion of the WindowedApplication itself. Therefore the WindowedApplication is still firing the resize events. The tiny window is a result of the minimse animation, with the window re-sized and positioned below the toolbar line as a result of the animation.

The solution to this then is simple, make sure when you update you stored values that the window is not currently minimised:

if(windowedApplication.nativeWindow.displayState != "minimized")
//update position and/or size

No comments:

Post a Comment