Archive

Archive for the ‘Mootools’ Category

Using swfObject with Mootools

August 4th, 2009

I'm sure most of us use swfObject, which in my opinion is the best option when it comes to embedding flash.

Lately I've been having a lot of fun with mootools and needed a way to embed flash dynamically. Basically I wanted my flash file to be embedded after a mootools click event was triggered.

So without further ado..

window.addEvent('domready', function() {
 
//get the div I want to embed my flash into.
var flashcontainer = $('flashcontainer');
 
//set all the flash properties
var file = 'file.swf';
var moviename = 'nameMyFlash';
var width = '640';
var height = '424';
var version = '9';
var bgcolor = '#000000';
 
//create the function that will fuse swfObject with mootools
var embedFlash = function(){
    var so = new SWFObject(file, moviename, width, height, version, bgcolor);
	     so.addParam("quality", "high");
	     so.addParam("align", "middle");
	     so.addParam("play", "true");
	     so.addParam("loop", "true");
	     so.addParam("scale", "exactfit");
             so.addParam("allowFullScreen", "true");
	     so.addVariable("variable1", "variable 1 value goes here");
	     so.addVariable("variable2", "variable 1 value goes here");
	     so.write(flashcontainer);
}
 
//get button by id
var myButton = $('mybutton'); 
 
// create click event to fire my function called "embedFlash()"
myButton.addEvent('click', embedFlash); 
 
});

And that's it.. Hope it helps....

You can download the latest tools used above from the links below:
MooTools - download release 1.2.3 or SWFObject 2.2

Post to Twitter Post to Plurk Plurk This Post Post to Yahoo Buzz Buzz This Post Post to Delicious Delicious Post to Digg Digg This Post Post to Ping.fm Ping This Post Post to Reddit Reddit Post to StumbleUpon Stumble This Post

Flashnutz ActionScript 2.0, ActionScript 3.0, Mootools , , ,

SEO Powered by Platinum SEO from Techblissonline