【发布时间】:2013-02-18 01:07:31
【问题描述】:
我有一个使用 FlashDevelop 创建的单窗口 AIR 应用程序,并希望它在用户关闭它时记住窗口的大小和位置。当它重新打开时,它会调整大小并转到那个位置。
找到一个可以执行此操作的 AS3 脚本,但我的应用程序没有 AS3。只有一个html和js文件。
当窗口关闭时,它应该保存窗口的状态,当它打开时,它应该加载保存的状态并调整大小/移动到保存的状态。这是我在 $(document).ready 上的内容
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;
当窗口关闭时,我希望我的函数保存窗口的状态,但无论我尝试什么函数都不会被调用:$(window).on("close"... 或 window.onclose= 或
...
<initialWindow>
<title>App Title</title>
<content>main.html</content>
...
所以我有以下问题:
- 如何向当前窗口添加事件监听器?
- 当前窗口加载时如何设置 x 和 y?
- 我能否像现在一样在窗口可见之前调整和移动窗口 似乎调整大小,但看起来有点片状,因为它最初打开 默认大小,然后调整为之前存储的值。
【问题讨论】:
-
window.nativeWindow.addEventListener(window.runtime.flash.events.Event.CLOSING, onCloseCommand);这将在窗口关闭时运行 onCloseCommand,现在要弄清楚如何保存和设置 x 和 y。
-
解决了,文档没有提到window.nativeWindow,但是在scripts/samples/window下的优秀空气样本jsairsamples.googlecode.com/files/air-samples.zip中找到了。太糟糕了,Adobe 关于 JavaScript 的 Flex 文档过时且不完整。
标签: javascript air