Recipe 3.5. 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 flash.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(flash.system.Capabilities.screenResolutionX); trace(flash.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 cellphone screen and a typical desktop computer display are different, so you should load different content based on the playback device.

var resX:int = flash.system.Capabilities.screenResolutionX; var resY:int = flash.system.Capabilities.screenResolutionY; // If the resolution is 240 x 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) ) {   var url:String = "main_pocketPC.swf"; } else {   var url:String = "main_desktop.swf"; } loader.load(new URLRequest(url));

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

var resX:int = flash.system.Capabilities.screenResolutionX; var resY:int = flash.system.Capabilities.screenResolutionY; // Set variables for the width and height of the new browser window. var winW:int = 200; var winH:int = 200; // Determine the X and Y values to center the window. var winX:int = (resX / 2) - (winW / 2); var winY:int = (resY / 2) - (winH / 2); // Create the code that, when passed to URLLoader.load(  ) // opens the new browser window. var jsCode:String = "javascript:void(          newWin=window.open('http://www.person13.com/'," +           "'newWindow', 'width=" + winW +          ", height=" +  winH + "," +           "left=" + winX + ",top=" + winY + "'));"; // Call the JavaScript function using a URLLoader object urlLoader.load(new URLRequest(jsCode));

Additionally, it is worth considering using the screen resolution values to determine whether or not to scale a movie. For example, when users have their resolution set to a high value, such as 1600x1200, some fonts may appear too small to read.




ActionScript 3. 0 Cookbook
ActionScript 3.0 Cookbook: Solutions for Flash Platform and Flex Application Developers
ISBN: 0596526954
EAN: 2147483647
Year: 2007
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net