2010-06-30 101 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()一起使用的正確事件。

相關問題