Mr__Mitch
Mr__Mitch

Reputation: 65

How can i invoke my own javascript API on my SWF dynamically embeded using swfOject?

I am using the swfObject library to dynamically embed a MP3 player i've made in Flash CS5. In the .fla file, i've declared a list of methods that can be called via Javascript (using the flash.external.ExternalInterface flash class).

That's not the problem since all these function work properly when called from Google Chrome's console. However, swfObject provides a way to invoke javascript API only if the .swf has been statically included (i.e. using swfobject.registerObject() ) but i can't find a way to achieve the same goal when the .swf is dynamically included (i.e. using swfobject.embedSWF() ).

Thanks in advance for your help and contibutions :)

Upvotes: 0

Views: 253

Answers (1)

HoLyVieR
HoLyVieR

Reputation: 11134

When you are using swfobject.embedSWF, you can specify the ID of the swf object in the attributes parameters :

swfobject.embedSWF(swfUrl, id, width, height, version, expressInstallSwfurl, flashvars, params, attributes, callbackFn)

Example :

swfobject.embedSWF(
    "YourFlash.swf", "WhereToPlaceThis", "0px", "0px", "10.0.0",
    "expressInstall.swf", {}, {}, { id : "IdOfTheSWF" },
    function () {
         var SWF = document.getElementById("IdOfTheSWF"); // That's your SWF //
         SWF.yourFlashFunction(); // And you can invoke function //
    }
);

Upvotes: 1

Related Questions