How To Use Javascript To Swap Swf In Html?
I embedded a swf in my html page, but I would like it to swap to another swf when I clicked on a button in html. I used swfobject.js to embed the swf, and I use prototype to write
Solution 1:
Using swfObject:
<divid='flashContent'></div><scripttype='text/javascript'>// Setup your initial flash var so = newSwfObject(.....);
so.write ('flashContent');
// Some event handler
someElement.onclick = function ()
{
// Load up the new SWF
so = newswfObject(....);
so.write('flashContent');
}
</script>
Solution 2:
How are you using SWFObject? If you use the swfobject.embedSWF method to add the SWF to your HTML file, then you can call that again with the same ID and it should remove the old Flash player object and add a new one with your new URL.
You also can use the SWF's own methods to replace the URL that it's using. If you've got the ID of the Flash object, use something like
var swf = getElementById("flash_id");
swf.LoadMovie(0, "http://example.com/newSwfUrl.swf");
and that should direct the Flash player to reload from a different location, replacing layer 0 (the default one). That may not work with really old Flash players, but should be fine in Flash 8 and later.
Post a Comment for "How To Use Javascript To Swap Swf In Html?"