Reputation: 2693
I'm trying to write a XML file to save the position and size of the app window in it. I'm running into this error:
TypeError: Error #1010: A term is undefined and has no properties. MainTimeline/setupWindow()
AS:
import flash.display.NativeWindowInitOptions;
import flash.display.NativeWindowSystemChrome;
import flash.display.NativeWindowType;
import flash.display.NativeWindow;
function setupWindow(e:Event = null):void
{
gotoLastPosition();
this.nativeWindow.addEventListener( Event.CLOSING, saveAppPosition );
}
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());
}
catch (e:Error)
{
//trace(error( e ));
}
finally
{
s.close();
}
}
function gotoLastPosition():void
{
var f:File = File.applicationStorageDirectory.resolvePath("appPosition.xml");
if (f.exists)
{
var s:FileStream = new FileStream();
try
{
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;
}
finally
{
s.close();
}
}
}
setupWindow()
What is wrong with the code?
Upvotes: 1
Views: 811
Reputation: 3338
It is call to setupWindow() that is causing the error, not the saveAppPosition method. It is executed as soon as your file is processed and nativeWindow is probably not yet ready.
Move setupWindow() call into a method (FlexEvent.CREATION_COMPLETE handler for instance) and try again.
Hope that helps.
Upvotes: 4