How can I call an Actionscript function when the .swf is referenced by jQuery?

百般思念 提交于 2019-12-06 09:51:48

I had the same problem. You can use $('#myflashelement').context.myactionscriptfunction(arg) to fix it. For convenience I made a jQuery 'plugin' to call them and to not rely on context in all of my code:

(function ($) {
    $.fn.callAS = function() {
        var func = arguments[0];
        var args = Array.prototype.slice.call(arguments, 1);
        return this.context[func].apply(this.context, args);
    };
})(jQuery);

You can call it with $('#myflashelement').callAS('myactionscriptfunction', arg).

I've never used the jquery swfobject plugin but if you give add an id param in the embed code you can access the the swf through

swf = document.getElementById("player"+i);
swf.callToFlash();
$('#myflashElement')[0].myASFunction(var1, var2);

works for me

$('#id_you_gave_swfobject').your_externalInterface_callback();

In jQuery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!