How can I call an Actionscript function when the .

2019-05-22 12:13发布

I have an .swf that I am embedding into HTML using the jQuery SWF Object plugin (http://jquery.thewikies.com/swfobject). I have a number of functions within the .swf that I need to call from within javascript functions. I've made these actionscript functions accessible to javascript by calling flash.external.ExternalInterface.addCallback(). Yet nothing happens when I make the call. I've had this happen before and it seems to be that when you reference the .swf from jQuery, you can't call flash functions. Is there anyway around this (aside from not using jQuery)?

Thanks.

4条回答
地球回转人心会变
2楼-- · 2019-05-22 12:27

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();
查看更多
够拽才男人
3楼-- · 2019-05-22 12:38

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).

查看更多
ら.Afraid
4楼-- · 2019-05-22 12:41
$('#id_you_gave_swfobject').your_externalInterface_callback();

In jQuery

查看更多
乱世女痞
5楼-- · 2019-05-22 12:46
$('#myflashElement')[0].myASFunction(var1, var2);

works for me

查看更多
登录 后发表回答