I am trying to call a function in a script action using the ExternalInterface.addCallback API, but I cannot get it to work. Here is what I have:
ActionScript:
//MyClass.as package { import flash.display.Sprite; import flash.external.ExternalInterface; public class MyClass extends Sprite { public function MyClass() { ExternalInterface.addCallback('getStringJS', getStringAS); } public function getStringAS():String { return "Hello World!"; } } }
NOTE. I compile this in swf using the mxmlc flex compiler, if that matters.
HTML / JavaScript:
<!doctype html> <html> <head> <title>User Identification</title> <head> <body> <object id="MyClass" name="MyClass" type="application/x-shockwave-flash" data="MyClass.swf" width="1" height="1"> <param name="movie" value="MyClass.swf"> <embed src="MyClass.swf" width="1" height="1"> </object> <script type="text/javascript"> var flash = document.getElementById("MyClass"); var str = flash.getStringJS(); alert(str); </script> </body> </html>
The error I am getting is:
Uncaught TypeError: Object
I also tried to add a timeout in case the swf file was not loaded, but I also did not succeed in this method.
Any thoughts?
Cheers
Mike
Swift source share