How to use javascript to swap swf in html?

左心房为你撑大大i 提交于 2020-01-11 09:47:13

问题


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 the javascript. I thought I can just do this

$('movie').value = 'swf/bhts.swf';
alert($('movie').value);

the value did change to swf/bhts.swf, but it is still playing the original swf file... this is the code I use to embed swf

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="530" height="298" id="flashcontent">
<param id="movie" name="movie" value="swf/trailer.swf" />
</object>

thanks.


回答1:


Using swfObject:

<div id='flashContent'>
</div>

<script type='text/javascript'>    
    // Setup your initial flash 
    var so = new SwfObject(.....);
    so.write ('flashContent');

    // Some event handler
    someElement.onclick = function ()
    {
         // Load up the new SWF
         so = new swfObject(....);
         so.write('flashContent');
    }
</script>



回答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.



来源:https://stackoverflow.com/questions/291647/how-to-use-javascript-to-swap-swf-in-html

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