【发布时间】:2010-07-13 07:31:58
【问题描述】:
这对我来说非常重要,因此我以一个简单的目标向悬赏提出问题:任何人都可以在 AJAX Air 中成功打开一个新的全屏 NativeWindow 并从该窗口检测击键吗?
希望我只是忽略了一些非常非常简单的事情,但是如果 JS 不能监听键盘事件,也许 Flash 小部件/助手可能能够将键盘事件传递给 JS。这是我唯一能想到的,但可能还有其他方法。我只是不知道。希望有人知道正确的答案!
更新
非常感谢@mwilcox 的回答。我不知道我使用的方法(来自 O'Reilly Cookbook)和createRootWindow() 之间有什么区别,但无论如何,它确实解决了我的问题。我最终使用的代码是这样的:
var objWindowOptions = new air.NativeWindowInitOptions();
objWindowOptions.transparent = false;
objWindowOptions.systemChrome = air.NativeWindowSystemChrome.STANDARD;
objWindowOptions.type= air.NativeWindowType.NORMAL;
var linkScreenToMainWindow = function() {
wWindow.removeEventListener(air.Event.COMPLETE,linkScreenToMainWindow);
objScreen.setWindowReference(wWindow.stage.getChildAt(0).window);
// At this point your windows are connected and you can fire commands into
// the window using objScreen as a proxy. For example:
alert(objScreen.document.body.innerHTML);
objScreen.myfunction();
};
var fhFilePath = air.File.applicationDirectory.resolvePath('childwindow.html');
wWindow = air.HTMLLoader.createRootWindow(true, objWindowOptions, true);
wWindow.stage.displayState = window.runtime.flash.display.StageDisplayState.FULL_SCREEN_INTERACTIVE;
wWindow.addEventListener(air.Event.COMPLETE,linkScreenToMainWindow);
wWindow.load(new air.URLRequest(fhFilePath.url));
我在 Adobe Air (JS) 中创建了一个新窗口,我需要捕获任何按键(或按键,如果更容易的话)。向主窗口添加事件侦听器没有问题,但任何子窗口似乎都无法识别任何常见的挂钩技术。
我认为部分问题在于addEventListener() 的第一个参数是事件的名称,并且所有记录在案的事件名称都未能引发任何事件。知道我应该怎么做吗?
主窗口
// Keyboard handler and event listener subscription:
var watcher = function() {
alert("Working");
};
window.addEventListener("keypress",watcher,false); // WORKS!
// Create child window:
var wWindow = new air.NativeWindow(objWindowOptions);
wWindow.activate();
wWindow.stage.displayState = window.runtime.flash.display.StageDisplayState.FULL_SCREEN_INTERACTIVE;
wWindow.stage.scaleMode = "noScale";
wWindow.stage.addChild( htmlView );
htmlView.load( new air.URLRequest("newpage.html") );
子窗口:newpage.html
// Keyboard handler and event listener subscription
var handler = function() {
alert('success!');
};
var strEventName = KeyboardEvent.KEY_DOWN; // Fails -- is undefined
//var strEventName = KeyboardEvent.KEYDOWN; // Fails -- is undefined
//var strEventName = 'keydown'; // Fails
// var strEventName = 1024; // Fails
window.nativeWindow.stage.addEventListener(strEventName,handler,false); // Fails
nativeApplication.addEventListener(strEventName,handler,false); // Fails
window.addEventListener(strEventName,handler,false); // Fails
我可能弄错了,但我想我已经尝试了上述的每一种排列,但它们都不起作用。
【问题讨论】:
标签: javascript events air