Reputation: 6057
We have an Adobe AIR application that sometimes loads a web page. On one of these web pages there is a hyperlink. When the hyperlink is clicked I want an AS3 function to be called. I know how to call a JavaScript function when the hyperlink is clicked, but within the JavaScript function how do I call my AS3 function?
In all the examples I can find the Flash is a SWF on the webpage and is thus inside a DOM element. So in the code examples they call the AS3 function on a DOM element like so:
function sendTextToAS3() {
var Txt = document.getElementById('htmlText').value;
var flash = document.getElementById("as3_js");
flash.sendTextFromJS(Txt);
document.getElementById('htmlText').value = "";
}
But in my case the Flash is not a SWF inside a DOM element, instead the Flash is the whole Adobe Air app and there is no DOM element with a SWF. So what do I call my AS3 function on if I can't do it via a DOM element?
Upvotes: 1
Views: 596
Reputation: 151
If you are using an mx:HTML
component to display your html page. Then you can call an as3 function from javascript using the following method:
Inside the html page, define the callback function:
var linkClicked = function () {}
Inside the as3 code, define the callback function:
function linkClicked():void {
// Your logic here
}
Inside the as3 code, override the definition of the callback function:
// var html:HTML = new HTML();
// load page ...
// when the page is loaded
html.domWindow.linkClicked = linkClicked;
For simplicity, the javascript linkClicked
function is defined on the window object.
Now, the as3 code is executed every time you call linkClicked
from javascript.
Upvotes: 0
Reputation: 532
Have a look at the ExternalInterface API. See examples from the docs at http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html#includeExamplesSummary
Upvotes: -1