Using SWFObject to embed Nimbb dynamically

If you are already using SWFObject in your project, you might want to add the Nimbb Player dynamically with it. In this example, when you click on the Add Player button, the Nimbb Player is added into the page and a Play Video button is displayed.

This example requires you to specify your developer key (see tutorial).

Example

Add Player

HTML code

<script src="http://www.google.com/jsapi"></script>
<script>google.load("swfobject", "2.1");</script>
<script language="JavaScript" type="text/javascript">
<!--

// Global variable to hold player's reference.
var _Nimbb;

// Event: Nimbb Player has been initialized and is ready.
function Nimbb_initCompleted(idPlayer)
{
  // Get a reference to the player since it was successfully created.
  _Nimbb = document[idPlayer];

  // Show button.
  document.getElementById("playBtn").style.display = "block";
}

// Add the Nimbb Player in the page using SWFObject.
function addPlayer()
{
  var idPlayer = "nimbb";
  var width = 320;
  var height = 240;
  var params = {allowScriptAccess: "always"};
  var attributes = {id:idPlayer, name:idPlayer};
  var flashvars = {
    guid: "XXXXXXXXXX",
    key: "YYYYYYYYYY",
    lang: "en"
    };

  // Add Nimbb Player.
  swfobject.embedSWF("https://player.nimbb.com/nimbb.swf", idPlayer, width, height, "9", null, 
    flashvars, params, attributes);

  // Hide button.
  document.getElementById("addBtn").style.display = "none";
}

// Start playback.
function play()
{
  _Nimbb.playVideo();
}

// -->
</script>
<a id="addBtn" href="javascript:addPlayer();">Add Player</a>
<a id="playBtn" href="javascript:play();" style="display: none;">Play Video</a>
<br>
<div id="nimbb"></div>

In the code, first notice that we load the script code from Google. In the addPlayer() function, we define a list of parameters. Notice that we define many of the Nimbb parameters under the flashvars variable. We call the swfobject.embedSWF() function to embed the Nimbb Player in the page.

At the end of the code, the nimbb div is where the Nimbb Player is located.

View more tutorials.

SIGN UP NOW 7-day free trial

Check out our Developer guide to get started with Nimbb.