XMLファイルを書き込んで、アプリケーションウィンドウの位置とサイズを保存しようとしています。私は、このエラーに実行しているよ:Adobe Air - ウィンドウのサイズと位置を保存する
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()
は、コードの何が問題になっているのですか?
... 'setupWindow()'はコードの一番下にあり、機能ブロックには入っていませんか? –
これは、functionlブロックに含まれていない底部に座っています。 ** this.nativeWindow.addEventListener(Event.CLOSING、saveAppPosition); **または** NativeApplication.nativeApplication.addEventListener(Event.EXITING、saveAppPosition); ** – Uli