HTML與AIR之間的溝通
還有重要的官方注腳:
The JavaScript environment has its own Document and Window objects. JavaScript code can interact with the AIR run-time environment through the runtime, nativeWindow, and htmlLoader properties. ActionScript code can interact with the JavaScript environment through the window property of an HTMLLoader object, which is a reference to the JavaScript Window object. In addition, both ActionScript and JavaScript objects can listen for events disptached by both AIR and JavaScript objects.
例子: (在JS中讓AIR的native window發出事件)
[js]
//似乎不能用自定事件, 可惜可惜,
//不然就可以直接利用事件處理把資料傳遞到AIR runtime了
var e = new air.Event(”foobar”);
window.nativeWindow.dispatchEvent( e );
[/js]
例子2: ( 在AIR中監聽 Javascript DOM 事件)
[as]
//只能監聽DOM預設事件//
HTML#htmlLoader.window.document.addEventListener(”click” , onClick );
[/as]
例子3: ( sandbox bridge , 取得不同sandbox的資料)
[js]
//在child html定義bridge
var interface = {};
interface.foobar = “blahblah….”;
window.childSandboxBridge = interface;
[/js]
[js]
//parent html裡頭, 取得定義好的bridge
var childInterface = {};
childInterface = document.getElementById(”myDIV”).contentWindow.childSandboxBridge;
air.trace( childInterface.foobar )
//as console output: blahblah…//
[/js]
Tags: AIR, javascript

