【问题标题】:Adobe Air - Save window size and positionAdobe Air - 保存窗口大小和位置
【发布时间】:2012-03-07 16:04:22
【问题描述】:

我正在尝试编写一个 XML 文件来保存应用程序窗口的位置和大小。我遇到了这个错误:

TypeError:错误 #1010:术语未定义且没有属性。 MainTimeline/setupWindow()

作为:

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() 位于代码底部,未封装在任何功能块中?
  • 它位于底部,没有包含在任何功能块中。我也不确定是否应该使用 this.nativeWindow.addEventListener(Event.CLOSING, saveAppPosition);NativeApplication.nativeApplication.addEventListener(Event.EXITING, saveAppPosition);

标签: actionscript-3 apache-flex air


【解决方案1】:

调用 setupWindow() 导致错误,而不是 saveAppPosition 方法。它会在您的文件处理完毕并且 nativeWindow 可能尚未准备好后立即执行。

setupWindow() 调用移入方法(例如 FlexEvent.CREATION_COMPLETE 处理程序)并重试。

希望对您有所帮助。

【讨论】:

  • 我正在 Adob​​e Flash CS 5 中构建应用程序。我尝试了这个“启动时”事件,但错误仍然出现:NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvokeEvent); // function onInvokeEvent(invocation:InvokeEvent):void { setupWindow() }
  • Event.ACTIVATE 我想应该可以工作(假设您的窗口是默认窗口)。
  • 我试过了,同样的错误出现了。不知道我做错了什么。
  • 我告诉过你,我认为 nativeWindow 是未定义的。尝试在 setupWindow() 中放置一个断点,以便您确认它。 gotoLastPosition() 也不应该工作。如果不是这种情况,请提供更多信息。
  • 你是对的。我该如何解决?我不明白为什么它没有定义。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-20
  • 2010-12-03
相关资源
最近更新 更多