Recipe 3.2.
Detecting the Operating System
Problem
You want
to know the operating system under which the Flash movie is being
played, perhaps to indicate which operating systems are not
supported or to implement a platform-specific feature.
Solution
Use the flash.system.Capabilities.os
property.
Discussion
In ActionScript 3.0, you can use the
flash.system.Capabilities.os property, which returns a
string indicating the operating system and version name. Possible
values include Windows XP, Windows 2000, Windows NT, Windows 98/Me,
Windows 95, and Windows CE. On the Macintosh, the string includes
the version number, such as Mac OS 9.2.1 or Mac OS X 10.4.4.
You can make design choices based on the
operating system. For example, your movie might load different
assets depending on the user's operating system. Or, you may simply
want to record the operating systems of the users who view your
movies for statistical analysis.
If all you care about is the general platform
type, instead of the specific version, you can check just the first
three letters of the string as follows:
var os:String = System.capabilities.os.substr(0, 3);
if (os == "Win") {
// Windows-specific code goes here
} else if (os == "Mac") {
// Mac-specific code goes here
} else {
// Must be Unix or Linux
}
|