Teppo Pihlajamäki logo
My life
Contact info 
My web pages
Magic trick 
Doggie game 
Chess clock 
Art gallery 
Find five errors 
Cryptogram game 

Flash version detection

Often Flash player version needs to be determined in actionscript to decide whether to continue playing the movie, or to stop it because the player doesn't have the necessary features.

On page http://www.macromedia.com/support/flash/ts/documents/version.htm Macromedia offers this solution:

playerVersion = eval("$version"); 
myLength = length(playerVersion);
while (i<=mylength) {
 i = i+1; 
 temp = substring(playerVersion, i, 1); 
 if (temp eq " ") { 
  platform = substring(playerVersion, 1, i-1); 
  majorVersion = substring(playerVersion, i+1, 1);
  secondHalf = substring(playerVersion, i+1, myLength-i);
  minorVersion = substring(secondHalf, 5, 2);

This code has some flaws:

  • Most seriously, it will cease to function correctly when Flash version number hits 10. It will return a one-digit number at variable majorVersion. In other words, it will believe that the version number is 1.
  • The code assumes that minorVersion is always two digits. (This may even be a correct assumption depending on Macromedia internal policies.)
  • It has some features that are now deprecated and may cease to function in future players. Comparison operator "eq" is one such feature, and hidden variable "$version" might be another, I don't know.
  • The while loop continues through the whole string even after it has found the substring it is looking for. This is not a serious flaw because this code is typically executed only once, but it is bad programming style nonetheless.

I have created my own code that fixes these issues. It can distinguish between Flash versions 5 and 6, and probably all future versions. Of versions 4 and earlier it can only detect whether the player is one of them. Macromedia code also can't distinguish between players prior to version 4.0r11.

First of all, the frame structure should be something like this:
1. preloader
2. preloader
3. version detection code
4. stop(); or majorVersion = 4; for player 4 and earlier
5. "onWithTheShow"

And here is the code:

var version = getVersion();
var space = version.indexOf(" ");
var comma1 = version.indexOf(",");
var comma2 = version.indexOf(",", comma1+1);
var comma3 = version.indexOf(",", comma2+1);
var platform = version.substring(0, space);
var majorVersion = version.substring(space+1, comma1);
var minorVersion = version.substring(comma2+1, comma3);
if ((majorVersion>=5) != false) {
	gotoAndPlay ("onWithTheShow");

You will notice the boolean expression (majorVersion>=5) != false, which seems unnecessarily complicated. Player 4 does not understand new comparison operators, and would go to frame "onWithTheShow". Double comparison will prevent that and make player 4 continue to the next frame. You might place a stop(); command there and prompt the user to upgrade his player. Alternatively you might place a majorVersion = 4; command there.

It is important that there is a preloader before this code. If frame "onWithTheShow" does not exist yet, playhead will go to the next frame even in new players. If there is a stop(); command in the next frame, the preloader may be built of new actionscript commands that player 4 doesn't understand, because player 4 will end up in stop frame anyway.

At least in Flash 5.0a Mac authoring environment, if you go to normal edit mode, getVersion() will be stripped of its parentheses, making the code to behave incorrectly.

Below is a simple Flash movie that attempts to recognize player version:

My YouTube-videos:

Playing poker
on television.

One hand

Hamster toy.