Article
Flash Player Detection Techniques Unearthed
Inbuilt Flash Player Version Detection
Flash ActionScript itself has three ways of detecting the version of the Flash Player on the client computer:
$version(introduced in Flash Player 4 release 11) returns an operating system string together with version information (eg WIN 6,0,79,0)getVersion()(introduced in Flash Player 5) returns a similar string to$version- System.capabilities.version (introduced in Flash Player 6) according to Macromedia returns a version number (eg 6.0) but in my testing it returns similar information to
$versionandgetVersion();
ActionScript's String methods allow the version information to be garnered from both $version and getVersion();
Which version detection method you use will depend on your target audience, something that cannot be stressed enough when developing Flash content for the Web.
Employing this method involves checking for the version number. If the version number is less than that required, take the user to a frame of the movie that displays some descriptive content and then prompts them to upgrade their browser. If the user has the required Flash Player, the movie can then continue loading.
Code example
Below is some ActionScript developed to handle the version detection. In my testing it worked well with Flash Player 4 and above. Flash Player 2 and 3 failed the test and displayed a blank movie -- probably due to the ActionScript used. Note that some of this code is used with the Server Side detection technique described further on in this article.
function checkPlayerAgainst(requiredPlayerVersion, thisPlayerId)
{
//----- first get the user's player information -------//
//make an array of the client player's version numbers
//thisPlayerId will be "WIN 6,0,21,0" or similar
thisVer = thisPlayerId.split(",");
//get rid of the gunk before the major player version number
//eg "WIN 6" etc - the first entry of the array will old OS information
thisVerSpaceNum = thisVer[0].indexOf(" ");
//finally, a major version number (eg 6)
thisMajorVer = Number(thisVer[0].substr(thisVerSpaceNum));
//---------------------------------------------------------------------//
//if the passed variable is not set
//or the major version number is equal to the minimum required
if(thisPlayerId == false || (thisMajorVer == requiredPlayerVersion))
{
gotoAndStop("upgrade");
}
//if the major version number found is greater than the required version
else if(thisMajorVer > requiredPlayerVersion)
{
//play the movie
gotoAndStop("init");
}
//default to upgrade information
else
{
gotoAndStop("upgrade");
}
}
This function is called by the following code:
//Flash Player <4 doesn't like >=
//so set minimum to 5 if checking for 6
//set minimum to 4 if checking for 5 and above
minimumVersion = 5;
//just for display
youNeed = minimumVersion+1;
//get the installed Player version
installedVersion = getVersion();
//less than Flash Player 5
if(installedVersion == "")
{
//debug = "mime type not found";
gotoAndStop("upgrade");
}
//Flash Player 5 or later
else
{
//Flash Player 6.0r65 or later and mime-type found
//the mime-type can be found using server side detection
if(skipVersionCheck=="true")
{
gotoAndStop("init");
//debug = "skipped version check as mime-type was found";
}
//Flash Player 5 or later and mime-type not found
else
{
//debug = "mime-type not found";
checkPlayerAgainst(minimumVersion, installedVersion);
}
}
stop();
When should this method be employed?
- When you are sure whether users will have Flash Player 4r11 installed as a minimum. Note that this method doesn't break with Flash 3 and 2 -- the movie starts but doesn't run, probably due to the ActionScript involved.
When should this method be avoided?
- When you may have a significant number of Flash Player 2 and 3 users (unlikely).
- When you want to provide markup based alternate content for users with less than the required Flash Player version.
This detection method fits neatly with what is probably the most elegant of all Flash Player detection scenarios, server side detection:
Server Side Flash Player Detection
This method uses scripting languages such as PHP, Coldfusion, Perl and the Microsoft stable of server side languages. No client side version detection is required, as this detection method can be handled internally by Flash ActionScript itself.
Macromedia's release notes for Flash Player 6 state that the Flash mime-type “application/x-shockwave-flash" is added to the HTTP-ACCEPT header when Flash Player 6 release 65 or later is installed on all available browsers. On the face of it this is great -- it takes Flash detection away from an unknown browser and places it in a stable, managed environment.
In practice, though, we find that this method still relies on support from browsers. Mozilla allows the mime-type to be written to its header, Internet Explorer 6 allows the same to happen but does not send the header when the page is refreshed, and no changes are made to Opera 7's header at all.
Don't worry. As with most things on the Web there is a workaround -- in this case relying on the Flash Player footprint and inbuilt version detection.
So how does this work?
The HTTP-ACCEPT header that's sent to the server includes a listing of all mime-types the browser can handle, such as text/html, image/gif etc. When the latest Flash Player is installed, it attempts to add this entry to the header:
“application/x-shockwave-flash"
Using PHP, for instance, we can check whether this string is present in the header:
<?php
//flash detection -- search the HTTP_ACCEPT string for the Flash mime-type.
//use $HTTP_ACCEPT for PHP versions <4.1
if(eregi("application/x-shockwave-flash", $_SERVER['HTTP_ACCEPT']))
{
$hasFlashSupport=true;
}
//eregi is the string (case insensitive) comparison function in PHP
//it will return a true or false depending on whether the substring is found
?>
What an elegant solution to Flash detection! If the variable $hasFlashSupport is set to true, we can assume that Flash Player 6 .0r65* or later is installed. We can also send markup to the browser based on what is found in the HTTP-ACCEPT header, rather than rely on client side scripts rendering alternate content, and so cut down on bandwidth issues associated with bloated client side scripts.
(* Flash Player 6.0r65 for Windows and Mac Classic, 6.0r67 for Mac OSX and 6.0r69 for Linux)
There is, however, a big problem with this solution. Anyone with a Flash Player that's lower than the above versions (including earlier releases of Flash Player 6), those using Opera, and users who refresh the page with Internet Explorer will be seen by the server side script to have no Flash Player installed!