开发者

Actionscript 3 javascript communication: Object #<HTMLEmbedElement> has no method

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.


Even though it might not fix your problem, I had a similiar problem with Chrome.

The fix was to replace

document.getElementById('flash').sendToActionscript('test');

with

((function(){return document.getElementById('flash');})()).sendToActionscript('test');

If the id attribute of the embed/object was flash and the function to call inside flash was sendToActionScript

I have no idea why this works.

Edit

This doesn't seem to always work. I found that creating the object using swfobject seems to always work for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜