AIR 跟 JS…
Sunday, July 26th, 2009當兩者糾纏在一起的時候,如果由AIR呼叫Javascript 會掛掉的話,可先試著用setTimeout,通常都可以解決。因為HTML DOM需要時間初始化,Javascript 才能被呼叫。
像是 setTimeout( domWindow.myJsFunction , 1000 );
當兩者糾纏在一起的時候,如果由AIR呼叫Javascript 會掛掉的話,可先試著用setTimeout,通常都可以解決。因為HTML DOM需要時間初始化,Javascript 才能被呼叫。
像是 setTimeout( domWindow.myJsFunction , 1000 );
更新@2009/5/11:
Adobe 有個驅動Garbage Collection的方法:
flash.system.System.gc();
flash.system.System.gc();
但是必須連續呼叫兩次,第一次呼叫: 對物件加上記號;第二次:清除記憶體
更多詳情請見:
http://www.craftymind.com/2008/04/09/kick-starting-the-garbage-collector-in-actionscript-3-with-air/
原文:
http://blogs.adobe.com/air/2009/05/performance_tips_for_adobe_air.html
在處理Grant Skinner發現的CPU效能問題之前,有幾個方法可以先改善AIR程式的效能:
更多文章:
DOM object in HTML ( HTML.domWindow ) stop the Drag events propagating so that dragging over HTML ui will not succeed, which means you cannot see an accept-drop-icon near mouse cursor. To solve this, you have to register a handler to prevent DOM doing something behind but accept drop action, as following sample code:
PS: Javascript drag event types:
dragover
dragenter
drop
ex: getElementById( “myBox” ).addEventListener( “dragover” , onOverBox );
寫AIR要用SQLite,可惜手冊上沒寫SQL syntax,加上我不會寫SQL,只有去找官方的語法了,如下:
SQL As Understood By SQLite
還有重要的官方注腳:
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]
安全性解釋文件
AIR 是個跨越各種環境的應用程式,看起來很簡單,要處理的事情多很多,目前第一個遇到的問題: sandbox
sandbox 像是程式碼的“活動空間“,基本上處於不同活動空間的程式碼理當無法互相溝通,但是,必要的時候,要想辦法讓他們可以交流, ex:
sandboxBridge
sandboxRoot, documentRoot…
有關在AIR使用Javascript有一個先天上的限制,
官方手冊提到:
Loading script files from outside the application sandbox is not permitted. No security error is generated. All script files that run in the application sandbox must be installed in the application directory. To use external scripts in a page, you must map the page to a different sandbox.
想利用js作為mash-up的根基,需要許多sandbox溝通和對照的程式碼。
萊恩‧史都華(Ryan Stewart)來到台北講演AIR了。
AIR的新功能不在這裡贅述了,可以在官方網站找到很多,或可以問問參加過Jeremy的網聚的朋友們,內容八九不離十,在短短的2小時內能說的東西不太多,點到為止吧。
他舉了一些網站:
他比我想像中的年輕點,領帶顏色很棒,哈。說話的速度也故意放慢許多,對於一個Evangelist來說這是必要的,他這次來的很匆促,不然可以推薦他去爬爬台灣百岳,讓他見識一下台灣山岳的狂野壯闊。
Next time, hold the conference here!
我問了個問題:
Adobe有沒有要設計可以顯示直書的TextField? 像是中文字可以直的書寫。
Ryan:
短期來說,不會。但是在之後會開放Text Renderer的API,讓開發人可以自訂文字在swf裡的繪製方法。
聽起來很棒,但是想想 自己寫 Text Rendering 的演算法不是件容易的事情呢! 不過我還是很期待。