Webeks.net - freelance programming
freelance programming - php, Joomla, Zend ...
Home :: Articles :: Programming :: javascript :: SWFobject - Flash loading twice workaround

SWFobject - Flash loading twice workaround

Written by Miha

I was solving an interesting problem for my client today. They wanted to show Flash on a flash-enabled sites but javascript slide-show on platforms that don't support flash. This is a task for swfobject that they managed to get running. However there was a problem with flash loading in Firefox - Flash loaded twice.

I looked around for a solution but nothing seemed to work. At last after few hours of trial and error I found the solution to this problem.

In SWFObject API there is embedSWF function explained.

  1. swfobject.embedSWF(swfUrlStr, replaceElemIdStr, widthStr, heightStr, swfVersionStr,
  2. xiSwfUrlStr, flashvarsObj, parObj, attObj, callbackFn)

The part that solved my clients problem is the callback function called after swfobject figures out whether browser supports flash or not.

  1. var flashvars = {};
  2. var params = {};
  3. var attributes = {};
  4.  
  5. function callbackFn(e) {
  6. if(!e.success) {
  7. //what to do if flash is not available
  8. //we can fill in the slideshow element or do a simple alert
  9. }
  10. }
  11.  
  12. swfobject.embedSWF("flash.swf", "slideshow", "900", "250", "9.0.0",
  13. false, flashvars, params, attributes, callbackFn);
  14.  
  15.  

Note that callback function is supported in SWFObject 2.2+ !


blog comments powered by Disqus