Categories:
| May 2012 | ||||||
|---|---|---|---|---|---|---|
| S | M | T | W | T | F | S |
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 | 31 | ||
Monthly Archives:
Most recent entries:
Syndicate:
SWFObject 1 and 2 compatible code
At our work we frequently have to work with deprecated code and frameworks, today I was confronted with the problem that I got code that has to run on a website with the latest SWFObject (2) and an older version (1), you probably know that both versions have another syntax for adding a SWF-object to the webpage.
Here is my small (and not perfect) solution:
/**
* Function that is compatible with the old 'new SWFObject()' and new 'swfobject.embedSWF'
* @return success
*/
function swfObjectCreate(swfPath, idName, width, height, className, path, settingFile, chartData, container)
{
log("swfObjectCreate() call");
container.attr("id", idName);
if(typeof SWFObject == "function")
{
var so = new SWFObject(swfPath, idName, width, height, "8", "#FFFFFF");
so.setAttribute("class", className);
so.addVariable("path", path);
so.addVariable("settings_file", settingFile);
so.addVariable("chart_data", encodeURIComponent(chartData));
so.write(idName);
}
else if(typeof swfobject == "object")
{
var flashvars = {
"path" : path,
"settings_file" : settingFile,
"chart_data" : encodeURIComponent(chartData)
};
swfobject.embedSWF(swfPath, idName, width, height, "9.0.0",
EXPRESS_INSTALL_PATH, flashvars,
{}, {"class":className}
);
}
else
{
log("No SWFObject found in Javascript");
return false;
}
return true;
}
function log(msg)
{
if(typeof console == "object")
{
console.log(msg);
}
}