2010-06-30 96 views
2

如何从创建它的父窗口发送消息或操作NativeWindow实例的内容?如何在Air中的两个NativeWindows之间进行通信

我已经阅读了几个在同一个应用程序中的NativeWindow实例之间进行通信的地方,您需要“维护LocalConnection或编写一整段JavaScript代码”。碰巧,我完全没有写过JavaScript的一些问题,但似乎没有关于如何去做的任何文档。有谁知道该怎么办?

感谢您给我的任何帮助!

回答

1

在这里回答我自己的问题。 “JavaScript的一个整体失衡”可以在一个荒谬的线来概括:

var myWindow = air.NativeApplication.nativeApplication.openedWindows[intWindowCount].stage.getChildAt(0).window 

myWindow.document.getElementById('status').innerHTML = "success"; 

这里假设你正在使用的NativeWindow和加载HTML到使用的HTMLLoader和你只加载一个孩子。 intWindowCount代表打开的窗口数量(包括Introspector)。 0表示您使用stage.addChild()方法创建的子项数。我正在使用的代码的全部内容如下。有可能一些清理的事情,但它应该成为任何一个很好的起点,需要做同样的事情:

var htmlView = new air.HTMLLoader(); 
    htmlView.width = 300; 
    htmlView.height = 500; 

    var objWindowOptions = new air.NativeWindowInitOptions(); 
    objWindowOptions.transparent = false; 
    objWindowOptions.systemChrome = air.NativeWindowSystemChrome.STANDARD; 
    objWindowOptions.type= air.NativeWindowType.NORMAL; 

    var wWindow = new air.NativeWindow(objWindowOptions); 
    wWindow.x = objScreen.x; 
    wWindow.y = objScreen.y; 
    wWindow.width = objScreen.width; 
    wWindow.height = objScreen.height; 
    wWindow.activate(); 

    wWindow.stage.align = "TL"; 
    wWindow.stage.displayState = runtime.flash.display.StageDisplayState.FULL_SCREEN_INTERACTIVE; 
    wWindow.stage.scaleMode = "noScale"; 
    wWindow.stage.addChild(htmlView); 
    htmlView.load(new air.URLRequest("pageTwo.html")); 


    setTimeout(function(){ 
     objScreen.setWindowReference(air.NativeApplication.nativeApplication.openedWindows[intWindowCount].stage.getChildAt(0).window); 
     objScreen.setClock(cClock); 
     cClock.screen = objScreen; 
    },500); 

超时末是一个可怕的,令人尴尬的黑客。我只使用它,因为我还没有找到与addEventListener()一起使用的正确事件。

相关问题