OK I am trying to make it so that when a user launches my air app, it positions itself and sizes itself to whatever it was the last time it was opened.
Here is my code:
private function init():void
{
gotoLastPosition();
this.nativeWindow.addEventListener( Event.CLOSING, saveAppPosition );
}
private function saveAppPosition(e:Event = null):void
{
var xml:XML = new XML('<position x="'+this.nativeWindow.x+'" y="'+this.nativeWindow.y+'" width="'+this.width+'" height="'+this.height+'"/>');
var f:File = File.applicationStorageDirectory.resolvePath("appPosition.xml");
var s:FileStream = new FileStream();
try
{
s.open(f,flash.filesystem.FileMode.WRITE);
s.writeUTFBytes(xml.toXMLString());
s.close();
}
catch(e:Error){}
}
private function gotoLastPosition():void
{
var f:File = File.applicationStorageDirectory.resolvePath("appPosition.xml");
if(f.exists)
{
var s:FileStream = new FileStream();
s.open(f,flash.filesystem.FileMode.READ);
var xml:XML = XML(s.readUTFBytes(s.bytesAvailable));
this.nativeWindow.x = xml.@x;
this.nativeWindow.y = xml.@y;
this.width = xml.@width;
this.height = xml.@height;
}
}
This does work, however, I am getting complaints from users that sometimes when they launch the app, it is no where to be found (off screen), they can right click the taskbar item and maximize it to get it back, but that should not be necessary.
I can only assume this issue is caused by my attempt to save the position of the application. I do not know what could be going wrong tho, or how I can fix this?
Maybe a way to tell if the app is off-screen after positioning it, and move it on-screen if so? Don't know how I can do that tho?
Any ideas?
Thanks!!!