O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2.4. Detecting Display Settings

Problem

You want to know the display settings for the device on which the movie is being played.

Solution

Use the screenResolutionX and screenResolutionY properties of the System.capabilities object.

Discussion

You should use the System.capabilities object to determine the display settings of the device that is playing the movie. The screenResolutionX and screenResolutionY properties return the display resolution in pixels.

// Example output:
// 1024
// 768
trace(System.capabilities.screenResolutionX);
trace(System.capabilities.screenResolutionY);

You can use these values to determine how to display a movie or even which movie to load. These decisions are increasingly important as more handheld devices support the Flash Player. For example, the dimensions of a cell phone screen and a typical desktop computer display are different, so you should load different content based on the playback device:

resX = System.capabilities.screenResolutionX;
resY = System.capabilities.screenResolutionY;

// If the resolution is 240   ×   320 or less, then load the PocketPC movie version.
// Otherwise, assume the device is a desktop computer and load the regular content.
if ( (resX <= 240) && (resY <= 320) ) {
  _root.loadMovie("main_pocketPC.swf");
}
else {
  _root.loadMovie("main_desktop.swf");
}

You can also use the screen-resolution values to center a pop-up browser window:

resX = System.capabilities.screenResolutionX; resY = System.capabilities.screenResolutionY; // Set variables ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required