I'm developing an AIR application in Flash that needs to call external javascript functions. Is it possible to call external js functions from AIR (Flash) or call js functions embedded in an html file? Any help or examples are appreciated.
I have an external .js file that contains functions that speaks to a third party application. What I would like to do is call to the functions in the .js file from my AIR app that is being developed in Flash.
If that's not possible, is it possible to re-write the javascript functions in an html file, load the html file into my AIR app (Flash) and call to them that way?
I'm able to load html files, I just can't seem to be able to call to the js functions. Again, this would be my second choice.
Thanks for any help.
Ok, I dont think you can call a JS file directly but load a simple HTML file like this:
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script language="javascript" type="text/javascript">
<!--
function addBlu(a, b) { return (a+b); }
-->
</script>
</head>
</html>
And with my poor AS3 code:
import flash.html.HTMLLoader;
import flash.net.URLRequest;
import flash.events.Event;
var html:HTMLLoader = new HTMLLoader();
html.load(new URLRequest("callJS.html"));
html.width = 0;
html.height = 0;
html.addEventListener(Event.COMPLETE, onLoaded);
addChild(html);
function onLoaded(e:Event) :void
{
trace("result (4+8) : "+e.target.window.addBlu(4, 8));
}
This will trace: result (4+8) : 12
Hope this help.
Hi,
Assuming you would like to build a JavaScript project that needs to use JQuery (or other JS framework) how would you proceed? You would include a .js file in some HTML files in which you need such support. Using this approach, you can use js framework functionality from js and html.
You can use this approach with AIR too (just like you are using AIRAliases.js or AIRIntrospector.js).
If i did not understand your workflow correctly, please provide me with more details and i will see if i can help you.
Regards,
Mihnea Ovidenie
AIR Engineering
I want to do the opposite of what you are describing.
I want to include a .js file into an .as or .mxml file
I then want to be able to execute that javascript file on any HTMLLoader that I have.
earlier it was shown that you can execute javascript from actionscript if the javascript is inside the html of the HTMLLoader like this:
function onLoaded(e:Event) :void
{
trace("result (4+8) : "+e.target.window.addBlu(4, 8));
}
but how would I call JQuery functions on the html inside the HTMLLoader if JQuery is not included in it.
Hi,
Instead of writting a jquery or javascript function inside a html page you can include your .js file in the index.template.html file which is generated by the air application <script language="javascript" src="your filename"></script>.
Then u can call the javascript function from your .as or mxml file like this
ExternalInterface.call(
functionname,arguments);
Thats it.
Thanks & Regards,
Flex Rock.
North America
Europe, Middle East and Africa
Asia Pacific