Get Flash player version with AS3

Recently I’ve posted on jumpeyecomponents’ Knowledge base an item, for the TxEff component, that shows you how to detect the version of the current Flash player, using ActionScript 3 code.

The only difference between AS2 and AS3 in this case is the method to get the Flash player’s version. AS2 has the getVersion() method. In AS3, there is the flash.system.Capabilities class which has a property called version. In both cases you’ll get a String representing the platform on which Flash player runs and the version. The result looks like this: “WIN 9,0,115,0″ (for the 9.0.115 Flash player on Windows).

What does this String mean ? Well, the first letters are the platform on which Flash player runs. This could be “WIN”, for Windows, “MAC” for Mac OS and “UNIX” for Unix based operating systems. Then comes the actual version number of the player. The first number represents the major version number. Next comes the minor version number. Third is the build number and the last one is the internal build number.

The next code snippet, separates the version String into the corresponding parts and displays them:

import flash.system.Capabilities;

// Get the player’s version by using the flash.system.Capabilities class.
var versionNumber:String = Capabilities.version;
trace(“versionNumber: “+versionNumber);

// The version number is a list of items divided by “,”
var versionArray:Array = versionNumber.split(“,”);
var length:Number = versionArray.length;

// The main version contains the OS type too so we split it in two
// and we’ll have the OS type and the major version number separately.
var platformAndVersion:Array = versionArray[0].split(” “);

var majorVersion:Number = parseInt(platformAndVersion[1]);
var minorVersion:Number = parseInt(versionArray[1]);
var buildNumber:Number = parseInt(versionArray[2]);

trace(“Platform: “+platformAndVersion[0]);
trace(“Major version: “+majorVersion);
trace(“Minor version: “+minorVersion);
trace(“Build number: “+buildNumber);