Embedding flash content with SWFObject

November 2nd, 2009 by Alex Leave a reply »

This note shows you how to embed the flash content properly in HTML using the SWFObject javascript library. In this particular case, we use version 2.2.

First step is to include the script in our html page:

<script type='text/javascript' language='JavaScript' src='swfobject.js'></script>

Next step is to place a container for our flash and define the id:

<span id='player'></span>

And finally, call the swfobject function embedSWF:

<script type="text/javascript">
var flashvars = {
  autostart: "yes",
  soundFile: "music.mp3"
};
var params = {
  allowScriptAccess: "always"
};
    swfobject.embedSWF("player.swf", "player", "300", "120", "9.0.0", flashvars, params);
</script>

Here, we create objects containing flashvars and object tag parameters, then pass it to the function.
First parameter of the embedSWF function is a path to our flash file, next one is the container id, width, height, flash movie version, and our flashvars and param objects. Basically objects here are just associative arrays.


Comments are closed.