简体   繁体   English

如何在Air中的两个NativeWindows之间进行通信

[英]How to communicate between two NativeWindows in Air

How can I send messages to or manipulate the contents of a NativeWindow instance from the parent window that created it? 如何从创建它的父窗口向该消息发送消息或操纵它的内容?

I have read several places that to communicate between NativeWindow instances in the same application you need to "maintain a LocalConnection or write a whole whack of JavaScript". 我已经读过几个地方,需要在同一应用程序中的NativeWindow实例之间进行通信,以“保持LocalConnection或编写完整的JavaScript代码”。 As it happens, I have no issue with writing a whole whack of JavaScript, but there doesn't seem to be any documentation on how to do it. 碰巧的是,我编写完整的JavaScript代码没有问题,但是似乎没有关于如何执行JavaScript的任何文档。 Does anyone know what to do? 有谁知道该怎么办?

Thanks for any help you can give me! 感谢你给与我的帮助!

Answering my own question here. 在这里回答我自己的问题。 "A whole whack of JavaScript" can be summed up in one ridiculous line: 可以用一条荒谬的话来概括“一整堆JavaScript”:

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

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

This assumes you are using NativeWindow and loading HTML into using HTMLLoader and you're only loading one child. 假设您正在使用NativeWindow并将HTML加载到HTMLLoader中,并且仅加载一个孩子。 intWindowCount represents the number of opened windows (including the Introspector). intWindowCount表示打开的窗口(包括Introspector)的数量。 0 represents the number of children you created using the stage.addChild() method. 0表示您使用stage.addChild()方法创建的子stage.addChild() The code I'm using is below in its entirety. 我正在使用的代码完整在下面。 There is likely some cleaning up to do, but it should be a good starting point for anyone that needs to do the same thing: 可能需要进行一些清理工作,但这对于需要执行相同操作的任何人来说应该是一个很好的起点:

    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);

The timeout at the end is a horrible, embarrassing hack. 最后的超时是一个可怕的,令人尴尬的骇客。 I'm only using it because I haven't found the right event yet to use with addEventListener() . 我之所以使用它,是因为我还没有找到与addEventListener()一起使用的正确事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM