我有一个使用FlashDevelop创建的单个窗口AIR应用程序,并希望它在用户关闭时记住窗口的大小和位置。当它重新打开时,它会调整大小并转到该位置。Adobe AIR应用程序记住并在JavaScript中设置窗口状态
找到了一个AS3脚本,可以做到这一点,但我的应用程序没有AS3。只有一个html和js文件。
当窗口关闭时,它应该保存窗口的状态,当它打开时,它应该加载保存的状态并调整大小/移动到保存的状态。以下是我对$(文件)。就绪
var width = screen.width;
var height = screen.height;
var p=new DOMParser();
var xml,x,y,windowWidth,windowHeight;
var f = window.runtime.flash.filesystem.File
.applicationDirectory.resolvePath("appPosition.xml");
if (f.exists){
var s = new window.runtime.flash.filesystem.FileStream();
try {
s.open(f,window.runtime.flash.filesystem.FileMode.READ);
xml=p.parseFromString(s.readUTFBytes(s.bytesAvailable),"text/xml");
x = parseInt(xml.childNodes[0].getAttribute("x"),10);
y = parseInt(xml.childNodes[0].getAttribute("y"),10);
windowWidth = parseInt(xml.childNodes[0].getAttribute("width"),10);
windowHeight =
parseInt(xml.childNodes[0].getAttribute("height"),10);
x = (x >= width) ? 20 : x;
y = (y >= height) ? 0 : y;
x = (x <= (width*-1)) ? 20 : x;
y = (y <= (height*-1)) ? 0 : y;
if (windowWidth >= (width-60) && windowHeight >= (height-60)) {
//the x and y are not set
window.runtime.flash.display.NativeWindow.x =20;
window.runtime.flash.display.NativeWindow.y = 0;
window.resizeTo(900,600);
// not yet sure if the following works
window.runtime.flash.display.NativeWindow.maximize();
}else{
// x and y don't do anything here either
window.runtime.flash.display.NativeWindow.x = x;
window.runtime.trace("sitting window x:",x);
window.runtime.flash.display.NativeWindow.y = y;
window.resizeTo(windowWidth,windowHeight);
}
}catch (e) {
window.runtime.trace(e.message);
}finally{
s.close();
}
return;
当窗口关闭我希望我的函数保存窗口,但无论我尝试的功能是从来没有所谓的状态:$(窗口)。 on(“close”...或window.onclose =或<文件onunluoad = ...冗长的指南似乎没有任何关于如何获取当前窗口的任何信息: http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/scripting/pdfs/javascript_tools_guide.pdf 创建窗口被覆盖,并且一旦拥有它你可以操纵它,但我从来没有创建一个窗口,application.xml看起来像这样:
...
<initialWindow>
<title>App Title</title>
<content>main.html</content>
...
所以我hav E以下问题:
- 如何事件侦听器添加到当前窗口?
- 如何在加载时设置当前窗口x和y?
- 我可以调整大小并移动窗口,因为它现在看起来像是 似乎调整大小,但看起来有点片状,因为它最初以 默认大小打开,然后重新显示为以前存储的值。
window.nativeWindow.addEventListener(window.runtime.flash.events.Event.CLOSING,onCloseCommand); 这将在窗口关闭时运行onCloseCommand,现在要弄清楚如何保存和设置x和y。 – HMR 2013-03-04 01:58:13
解决了它,文档没有提到window.nativeWindow,但在脚本/ samples/window下的优秀空气样本http://jsairsamples.googlecode.com/files/air-samples.zip中找到它。太糟糕了,Adobe在JavaScript方面有这么过时和不完整的文档。 – HMR 2013-03-04 02:36:38