Clearing an SWFObject Instance

A coworker of mine today was having trouble dynamically loading a Flash movie using the SWFObject. Actually he was having problems loading a new one once the first one was loaded.

Here is the situation, the web page loads, the user clicks a link (any trigger will work just fine) to load the first movie. Then the user clicks a different link to load a different movie, but nothing changes. The SWFObject will not let go of the div that it was loaded into. Heres how you get around this.

You first remove the child div from the DOM then recreate the div before the SWFObject tries to load the flash movie in it.

  1. function loadvid(thefile, theCatagory){
  2.     var div = document.getElementById('clipPlayer');
  3.          div.parentNode.removeChild(div);
  4.     var newdiv = document.createElement(div);
  5.          newdiv.setAttribute('id','clipPlayer');
  6.          newdiv.innerHTML = '';
  7.          document.body.appendChild(newdiv);
  8.     var so = new SWFObject('best_player.swf', 'clipPlayer', '250', '65', '6', '#ffffff');
  9.           so.addVariable('clipName', thefile);
  10.           so.addVariable('clipInfo', theCatagory);
  11.           so.addVariable('cacheKill', '');
  12.           so.write("clipPlayer");
  13. }

The only problem with this is that when it recreates the div it does so at the bottom of the page. I will work on how to place the div where you need it.

This entry was posted on Thursday, November 2nd, 2006 at 2:35 pm and is filed under Web Design. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

 

Leave a Reply