I have a flash that municates with a javascript using ExternalInterface. I have converted this into HTML5 using swiffy. How do call the methods i have created in flash using javascript?
I have a flash that municates with a javascript using ExternalInterface. I have converted this into HTML5 using swiffy. How do call the methods i have created in flash using javascript?
Share Improve this question asked Jan 10, 2013 at 10:39 Jon FabianJon Fabian 2862 silver badges15 bronze badges3 Answers
Reset to default 7Here is an update to the answer for who is still looking: As of now, Swiffy 5.3 has already supported ExternalInterface. I am able to make javascript call from AS3 using:
ExternalInterface.call("jsFunction", args);
In js, you just need to declare the "jsFunction" :
<script>
function jsFunction(args) {
alert("Call from AS3");
}
</script>
For the reverse direction, calling from JS to AS3 through Swiffy can be achieved using this in AS3:
ExternalInterface.addCallback("nameForJS", closeFunction);
function closeFunction(s:String) {
trace("Received " + s + " from js");
}
In JS, you will need to get the DOM el that tight to swiffy, and execute the function from there:
document.getElementById("swiffycontainer").nameForJS();
Hope this helps!
As per the swiffy documentation, ExternalInterface is not supported for AS 2.0 or AS 3.0 by swiffy.
Please refer to:
ActionScript 2.0 support
ActionScript 3.0 support
Still, it is easy to call JavaScript function from AS3-to-HTML5-via-Swiffy :
var urlRequest : URLRequest = new URLRequest( "javascript:doRoo();" );
navigateToURL( urlRequest,'_self' );
What is the best way to call a function that was declared in AS3 pre-swiffy from JavaScript - basically the reverse?