简体   繁体   中英

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". 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. 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:

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. intWindowCount represents the number of opened windows (including the Introspector). 0 represents the number of children you created using the stage.addChild() method. 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() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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