简体   繁体   中英

Why can't I create and destroy an swf object more than twice in this Javascript

Why can't I create and destroy an swf object more than twice in this Javascript

Any clues? I'll appreciate your advise.

var player = null;
function playerReady(thePlayer) {
    player = window.document[thePlayer.id];
}

function createPlayer(station) {
  //if (player) {  }
  swfobject.removeSWF('player1');

  if (!player) {
    var d = document.createElement("div");
    d.setAttribute("id", "streamPlayer");
    document.getElementById("content-container").appendChild(d);
  }

  var flashvars = { file: station, type: "sound", autostart: "true"  }
  var params = { allowfullscreen: "true", allowscriptaccess: "always" }
  var attributes = { id: "player1",  name: "player1" }

  swfobject.embedSWF("player.swf", "streamPlayer", "320", "20", "9.0.115", false, flashvars, params, attributes);
  }
var player = null;
function playerReady(thePlayer) {
    player = window.document[thePlayer.id];
}

function createPlayer(station) {
  //if (player) {  }
  swfobject.removeSWF('player1');

  var d = document.createElement("div");
  d.setAttribute("id", "streamPlayer");
  document.getElementById("content-container").appendChild(d);

  var flashvars = { file: station, type: "sound", autostart: "true"  }
  var params = { allowfullscreen: "true", allowscriptaccess: "always" }
  var attributes = { id: "player1",  name: "player1" }

  swfobject.embedSWF("player.swf", "streamPlayer", "320", "20", "9.0.115", false, flashvars, params, attributes);
  }

When you remove player1, it removes the streamPlayer div, which isn't added back in when createPlayer runs again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM