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= または <document 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>
...
だから私は次の質問があります:
- 現在のウィンドウにイベント リスナーを追加するにはどうすればよいですか?
- ロード時に現在のウィンドウ x と y を設定するにはどうすればよいですか?
- 現在、サイズが変更されているように見えますが、最初はデフォルトのサイズで開き、以前に保存された値にサイズ変更されるため、ウィンドウが表示される前にサイズを変更して移動できますか。