I'm trying to call an Actionscript 3 method from Javascript but Chromes gives the error below:
Object #<HTMLEmbedElement> has no method
I put my SWF to the page as below:
<embed type="application/x-shockwave-flash" src="/subfolder/flash.swf" width="550" height="400" id="myFlash" name="myFlash" bgcolor="#FFFFFF" quality="high" />
Actionscript 3 Code:
function query(fn:String, ln:String):void {
a_txt.text = fn + " " + ln;
}
ExternalInterface.addCallback("queryFlash", query);
And finally Javascript:
function getFlashMovie(movieName) {
var isIE = navigator.appName.indexOf("Microsoft") != -1;
return (isIE) ? window[movieName] : document[movieName];
}
$(document).ready(function() {
getFlashMovie("myFlash").queryFlash("a", "b");
});
Am I missing something here?
jQuery's ready()
corresponds to the DOMContentLoaded
event. That means that the HTML page finished loading and you can access the DOM - but it doesn't guarantee you that all the embedded images and objects finished loading. So your Flash probably simply didn't load yet. You should listen to the window's load
event instead.