I will describe the method I used for detecting Flash and putting the version of Flash detected in a session variable.
There are lots of different ways you could do this. This method made sense on my site http://hindiwallah.com
Note that this method is meant for detecting versions of Flash higher than 6.0.0.0 You could easily make it work for versions of Flash from 5 consult the Flash documentation for actionscript that will work in version 5.0.0
Here is the code I've put in my theme where the logo will appear :
<?php
if (!isset($SESSION->flash_version) || ($SESSION->flash_version == "none"))
/// if no flash has been detected yet
{ ?>
<img src="<?php echo "$CFG->wwwroot/theme/$CFG->theme/"?>pictures/wallah_static.jpg">
<?php
if (!isset($SESSION->flash_version))
{ ///if we haven't yet tried to detect flash version try now.
$SESSION->flash_version = "none"; /// set flash_version to none. It will stry this way if the following flash movie doesn't load.
?>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="1" height="1" id="wallah" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="<?php echo "$CFG->wwwroot/theme/$CFG->theme/flashversion.swf" ?>"/>
<param name="quality" value="high" />
<param name="bgcolor" value="#ffff99" />
<param name="FLASHVARS" value="flashversionpath=<?php echo "$CFG->wwwroot/theme/$CFG->theme/flashversion.php?random=".rand(1,10000) ?>" />
<embed src="<?php echo "$CFG->wwwroot/theme/$CFG->theme/flashversion.swf" ?>" quality="high" FLASHVARS="flashversionpath=<?php echo "$CFG->wwwroot/theme/$CFG->theme/flashversion.php?random=".rand(1,10000)?>" bgcolor="#ffff99" width="1" height="1" name="wallah" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" />
</object>
<?php
}
} else
{
?>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="280" height="105" id="wallah" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="<?php echo "$CFG->wwwroot/theme/$CFG->theme"?>/pictures/wallah.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffff99" />
<embed src="<?php echo "$CFG->wwwroot/theme/$CFG->theme"?>/pictures/wallah.swf" quality="high" bgcolor="#ffff99" width="280" height="105" name="wallah" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
<?php
} ?>
If $_SESSION->flash_version has not been set at all we load in our Flash version detection movie and display the jpg logo, this means when you first enter my site you will not see the Flash logo but will always see a jpg logo.
If it has been set to 'none' this means we've attempted to detect Flash already and it appears no Flash is present so we load the jpg instead of the Flash logo. We only try to detect Flash once.
Flash detection works as follows :
- I set session varialbe flash_version to 'none'in the html page but then load my flashversion.swf Flash movie.
- The 'flashversion.swf' movie is invisible on the page it is 1 pixel by 1 pixel. The only thing it does it call up another page 'flashversion.php' and pass the version of Flash detected to the script. So the movie just consists of this code on frame 1 ('flashversionpath' is passed into the movie as a Flashvar and is the path to the php script to load) :
loader = new LoadVars(); loader.flash_version=getVersion(); loader.sendAndLoad(flashversionpath, loader , "POST");
-
Then the php script I load is also very simple. Here it is :
<?php ///Opened by flashversion.swf require_once("../../config.php"); $SESSION->flash_version = $_POST['flash_version']; ?>
So if the Flash movie loads it calls up a php script that sets the session variable. If not then the session variable remains set to 'none'. This might seems a little complex but I think is probably the easiest method of reliably detecting the presence of Flash. It is similar to the method that Macromedia recommmends. One potential problem with this method might be if the user clicks past the first page before the Flash detection movie loads, then no Flash will be detected. Since the Flash detection movie is only 1 KB this hopefully shouldn't happen too often. If you're just using Flash for prettying up your site this is not too much of a problem. But you should be aware that the method might fail sometimes and you should give the user a way to tell your site to check again for Flash when critical parts of your site are using Flash.
I've attached the files flashversion.fla, flashversion.swf, flashversion.php and header.html (only the relevant bits) from my theme as a zip file.