Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pfeilbr/338593 to your computer and use it in GitHub Desktop.
Save pfeilbr/338593 to your computer and use it in GitHub Desktop.
Adobe AIR HTML Control <-> JavaScript Communication Example
<?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>
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();
}
}
}
@ncd76
Copy link

ncd76 commented Mar 11, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment