Created
March 20, 2010 10:06
-
-
Save pfeilbr/338593 to your computer and use it in GitHub Desktop.
Adobe AIR HTML Control <-> JavaScript Communication Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()"> | |
<mx:HTML left="10" top="10" bottom="10" right="10" id="html"/> | |
<mx:Script> | |
<![CDATA[ | |
private function init():void { | |
html.addEventListener(Event.COMPLETE, this.htmlComplete); | |
html.htmlText = Helper.html(); | |
} | |
private function htmlComplete(event:Event):void { | |
// air -> js | |
html.domWindow.foo(); | |
// air -> js -> air | |
html.domWindow.callback(function():String { | |
var msg:String = "callback here!"; | |
trace(msg); | |
return msg; | |
}); | |
// air -> delayed js -> air | |
html.domWindow.saveCallback(function():String { | |
var msg:String = "callback2 here!"; | |
trace(msg); | |
return msg; | |
}); | |
} | |
]]> | |
</mx:Script> | |
</mx:WindowedApplication> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
public class Helper | |
{ | |
public function Helper() | |
{ | |
} | |
public static function html():String { | |
return ( | |
<![CDATA[ | |
<html> | |
<head> | |
<script> | |
function foo() { | |
alert("foo"); | |
} | |
function saveCallback(cb) { | |
window.cb = cb; | |
setTimeout(callCallback, 3000); | |
} | |
function callCallback() { | |
window.cb(); | |
} | |
function callback(fn) { | |
alert( fn() ); | |
} | |
</script> | |
</head> | |
<body> | |
<a href="#" onclick="callCallback();">callCallback</a> | |
</body> | |
</html> | |
]]> ).toString(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, quick question(s) if I may: In the body can an image added (from local file system) and a .js file in the same directory as Helper?? Thanks