我正试图编写一个XML文件来保存应用程序窗口的位置和大小。我遇到了以下错误:
TypeError:错误#1010:术语未定义且没有属性。主时间线/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()
代码出了什么问题?
导致错误的是对setupWindow()的调用,而不是saveAppPosition方法。它会在处理完文件后立即执行,并且本机窗口可能还没有准备好。
将setupWindow()调用移动到方法(例如FlexEvent.CREATION_COMPLETE处理程序)中,然后重试。
希望能有所帮助。