问题
I have a flash that communicates 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?
回答1:
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
回答2:
Here 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!
回答3:
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?
来源:https://stackoverflow.com/questions/14255937/calling-a-flash-externalinterface-in-swiffyobject