2012-03-07 5 views
1

XMLファイルを書き込んで、アプリケーションウィンドウの位置とサイズを保存しようとしています。私は、このエラーに実行しているよ:Adob​​e 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() 

は、コードの何が問題になっているのですか?

+0

... 'setupWindow()'はコードの一番下にあり、機能ブロックには入っていませんか? –

+0

これは、functionlブロックに含まれていない底部に座っています。 ** this.nativeWindow.addEventListener(Event.CLOSING、saveAppPosition); **または** NativeApplication.nativeApplication.addEventListener(Event.EXITING、saveAppPosition); ** – Uli

答えて

4

これはエラーではなく、saveAppPosition方法を引き起こしているsetupWindowに()の呼び出しあります。ファイルが処理されるとすぐに実行され、nativeWindowはまだ準備ができていません。

move setupWindow()メソッド(FlexEvent.CREATION_COMPLETEハンドラなど)を呼び出して、やり直してください。

希望に役立ちます。

+0

を使用する必要があるかどうかもわかりません。 Adobe Flash CS5のアプリケーションです。この「起動時」イベントを試しましたが、エラーが表示されます。 'NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE、onInvokeEvent); // 関数onInvokeEvent(呼び出し:InvokeEventの):無効{ setupWindow() } ' – Uli

+0

にEvent.ACTIVATEは、私は(あなたのウィンドウはデフォルトの1であると仮定)と仮定動作するはずです。 –

+0

私はそれを試み、同じエラーが表示されます。私が間違っていることを確信していない。 – Uli

関連する問題