How can I call an ActionScript function when jQuery is referencing the .swf?

I have a .swf that I am embedding in HTML using the jQuery SWF Object plugin ( http://jquery.thewikies.com/swfobject ). I have a number of functions inside .swf that I need to call from javascript functions. I made these actionscript functions available to javascript by calling flash.external.ExternalInterface.addCallback (). But nothing happens when I call. This has happened before, and it seems that when you reference the .swf from jQuery, you cannot call flash functions. Anyway, around this (other than using jQuery)?

Thank.

+2


source to share


4 answers


I had the same problem. You can use $('#myflashelement').context.myactionscriptfunction(arg)

to fix this. For convenience, I made a jQuery 'plugin' to call them and 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)

.

+1


source


I've never used the jquery swfobject plugin, but if you add the id parameter to the embed code, you can access the swf via



swf = document.getElementById("player"+i);
swf.callToFlash();

      

+3


source


$('#myflashElement')[0].myASFunction(var1, var2);

      

works for me

+1


source


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

      

In jQuery

0


source







All Articles