Interesting problem (and of course by “interesting” I mean “frustrating”).
I’m using SWFObject to display a flash movie, and that’s fine. Now I’m trying to use external interface to pass a variable via JavaScript.
Here’s the JavaScript code:
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
swfobject.registerObject("tab", "9.0.0");
window.onload = function () {
var swf = swfobject.getObjectById("tab");
swf.asFunc("10");
}
</script>
Now I get one of two errors (seems to be random): “swf.asFunc is not a function” or “uncaught exception: Error calling method on NPObject! [plugin exception: Error in Actionscript. Use a try/catch block to find error.].”
Here’s my ActionScript (on frame 1 of the root of the .swf):
import flash.external.ExternalInterface;
ExternalInterface.addCallback("asFunc", this, asFunc);
function asFunc(str:String):Void {
widthBox.text = str;
}
What am I missing?