version:
SWiSHmax
build date: 2004.08.12
SWF usage: 5+
Flash Player Version Detection
There is nothing new about Flash player version detection.
I've seen a lot of different scripts and tutorials on the internet. Unfortunately,
most of them are far too bloated and complicated - in my opinion, of course.
This tutorial will hopefully supply you with the necessary code in the
most simple way possible.
Why ?
Not everyone needs to use Flash player version detection
in their movies - you might not need this at all. It does have its place
though, in certain applications. Some scripts will require a certain version
of the Flash player in order to function properly. In some instances,
a movie will function fine with a certain version but could have enhancements
or added functionality with a later version of the Flash player. Streaming
video often requires version 6 of the Flash player, but the rest of the
site could function fine with only version 5 of the Flash player.
How ?
It all begins with the actionscript method $version.
When assigned to a variable, the $version method
will return a string containing information on the Flash player version.
This information includes several parts: the platform (operating system);
the major version number of the player; and, the minor version number.
Example:
WIN 6,0,21,0
Note: When debugging inside SWiSHmax,
the internal player will return a value of: SWiSH 6,0,0,0
The value is always returned in the same format:
platform + blank space + major version number + comma + zero + comma +
minor version + comma + zero
Open a new blank movie in SWiSHmax. Open the Script panel
and select 'Expert' mode (if 'Guided' mode is displayed, click on it and
select 'Expert' from the drop-down menu). In Expert mode, you can simply
paste in the scripts found in this tutorial (rather than having to manually
add each line).
Add the following script:
onFrame(1)
{
verInfo = $version;
trace(verInfo);
} |
Press the Play button on the Control toolbar and open
the Debug panel to view the output.
Press the Stop button on the Control toolbar.

With a consistent format like this, it is fairly easy
to extract each component by using arrays.
First, we'll take the value of $version and split it into
two parts. We do this by using string.split().
onFrame(1)
{
verInfo = $version;
verInfo = verInfo.split(" ");
trace(verInfo);
} |
Press the Play button on the Control toolbar and open
the Debug panel to view the output.
Press the Stop button on the Control toolbar.
By splitting the string with " " (a blank space),
it creates an array with two values - the platform information, and the
rest.

Now that we have two elements in the array - it is very
easy to get the platform information by using: arrayName[0] (retrieves the
first element in the array). However, the second element (array[1]) still
contains both the major and minor version (not to mention the two added
zeros). Well, by following the same steps we did to split the array in
the first place, we can split the second element even further.
onFrame(1)
{
verInfo = $version;
verInfo = verInfo.split(" ");
fpInfo = verInfo[1].split(",");
trace(fpInfo);
} |
Press the Play button on the Control toolbar and open
the Debug panel to view the output.
Press the Stop button on the Control toolbar.

Using the diagram above, you can see that it is now very
easy to access both the major version number (array position 0) and the
minor version number (array position 2).
Let's take these arrays and assign variables to each element
that we may need for the detection.
onFrame(1)
{
verInfo = $version;
verInfo = verInfo.split(" ");
oS = verInfo[0];
fpInfo = verInfo[1].split(",");
majVer = fpInfo[0];
minVer = fpinfo[2];
trace("OS: " add oS);
trace("Major: " add majVer);
trace("Minor: " add minVer);
} |
Press the Play button on the Control toolbar and open
the Debug panel to view the output.
Press the Stop button on the Control toolbar.
Note: All these trace statements are
not vital to the functionality of the script, but they do help for debugging
purposes.
What Next ?
Now that you have access to three different pieces of
information regarding the Flash player version, you can use it any way
that you need. You can determine what version of the Flash player the
viewer has then decide whether or not they can proceed or if they need
to update their Flash plugin. You can achieve this through the use of
basic IF conditionals.
Using the script from the last step, we ended up with
three variables containing each of the three main elements:
oS = platform (operating system)
majVer = major flash player version number
minVer = minor flash player version number
Depending on which version you want to require that the
viewer is using, you can use the 'majVer' variable. You can also get much
more specific with the 'minVer' variable (many major versions of the Flash
player have had minor updates - which are reflected by the minor version
number). You can also perform actions based on which platform the viewer
is running (certain scripts cannot be run on Macintosh systems, for example).
Here is one example designed to check for a specific major
version of the Flash player and alert the viewer if they are running a
version prior to the required version.
onFrame(1)
{
verInfo = $version;
verInfo = verInfo.split(" ");
oS = verInfo[0];
fpInfo = verInfo[1].split(",");
majVer = fpInfo[0];
minVer = fpinfo[2];
if (majVer < 21) {
javascript("alert('We recommend that
you update your Flash player plugin at http://www.macromedia.com')");
} else {
javascript("alert('Congratulations, your
Flash player plugin is up to date!')");
}
} |
Use File Menu --> Test in Browser in order to test
this script.
Note: As you can see, that code checks
for Flash player version 21 - which does not exists.
Using the script above, change the IF conditional to check
for version 4 instead.
Use File Menu --> Test in Browser in order to test
this script.
You can also check for the Platform.
onFrame(1)
{
verInfo = $version;
verInfo = verInfo.split(" ");
oS = verInfo[0];
fpInfo = verInfo[1].split(",");
majVer = fpInfo[0];
minVer = fpinfo[2];
if (oS == "WIN") {
javascript("alert('Is that you Bill?')");
} else {
javascript("alert('Bill who?')");
}
} |
Use File Menu --> Test in Browser in order to test
this script.
If you are running a Windows operating system, you should
see the "Is that you Bill?" javascript message. If you're running
something else (Macintosh or Unix), you should see the "Bill who?"
message.
You're certainly not limited to using Javascript alerts
- you can do anything you want ... display a message, display an 'Update
Flash Plugin' button, skip to a different frame or scene, or ignore the
information entirely ... the choice is yours !
|