Detecting whether the Flash player is installed and sending fallback content if it is not

Detecting whether the Flash player is installed and sending fallback content if it is not

by Jamie Pratt -
Number of replies: 9

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.

 

Average of ratings: -
In reply to Jamie Pratt

Re: Detecting whether the Flash player is installed and sending fallback content if it is not

by Jamie Pratt -
Of course you can use the flashversion session variable throughout the rest of your site as well.

It might also be a good idea to use this xhtml compliant method to embed your Flash movies in your html page :

http://www.alistapart.com/articles/flashsatay/

In reply to Jamie Pratt

Re: Detecting whether the Flash player is installed and sending fallback content if it is not

by Jamie Pratt -
Note to myself : I should be using the Flash Satay method to embed FLash movies in html in my TUI and Flash Activity module and also to embed the Flash detection movie in my theme.
In reply to Jamie Pratt

An alternative to Flash satay

by Helen Foster -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
An alternative to the Flash satay method is Hixie's method:

http://ln.hixie.ch/?start=1081798064&count=1

The code is more bloated, however it seems to work more reliably than the Flash satay.
In reply to Helen Foster

Re: An alternative to Flash satay

by Jamie Pratt -
Hi Wild Girl,

it seems to work more reliably than the Flash satay.

In which situations doesn't the Flash satay method work reliably?

Jamie
In reply to Jamie Pratt

Re: An alternative to Flash satay

by Helen Foster -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
e.g. in some installations of IE 5.5  a text area is displayed.

The codebase attribute provides useful functionality in IE, ensuring users have a specific version of Flash player.
In reply to Helen Foster

Re: An alternative to Flash satay

by Jamie Pratt -
e.g. in some installations of IE 5.5 a text area is displayed.

Thanks for the info.
In reply to Helen Foster

Re: An alternative to Flash satay

by Jamie Pratt -
I checked out that method on http://validator.w3.org/ It's not valid xhtml (it was written to be valid html 4.0) but the only problem seems to be that the param tags aren't closed. See here.



In reply to Jamie Pratt

Re: An alternative to Flash satay

by Helen Foster -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
You can easily add trailing slashes to the param name tags if you need it to be valid xhtml. smile
In reply to Jamie Pratt

Re: Detecting whether the Flash player is installed and sending fallback content if it is not

by Timothy Takemoto -

I recently found out that TUI is also a popular, perhaps the most popular, brand beer sold in New Zealand.

They have adversts showing a group of burly rugby player men gawping "pints" (actually New Zealand's beer has gone metric but they still seem to use the word) of TUI while ravashing blondes looky lusty and folorn in the background. The caption reads "TUI the hottest jugs in the bar." I believe that "jugs" refers to the beer glasses.