User Resolution Detection
| Category | : Flash | Views | : 12880 | ||
| Version | : 8 | Rating | : | ||
| Type | : Text | Source File | : user-resolution-detection.zip | ||
| Result | : See the result | ||||
Sometimes you may have a movie that requires a certain resolution to play, using this code you will be able to tell whether the user is using the resolution you want and then run the code.
You won't be able to change the resolutions as they are ready only, but knowing the resolution is really good.
Paste this code on the main timeline:
//stop the frames.
stop();
var res = System.capabilities.screenResolutionX + " x " + System.capabilities.screenResolutionY
var resX:Number = System.capabilities.screenResolutionX;
_root.gotoAndStop("res" + resX);
This set the variable "res" to the resolution:
var res = System.capabilities.screenResolutionX + " x " + System.capabilities.screenResolutionY
System.capabilities.screenResolutionX is the width of the screen resolution; it can be 800, 1024, 1152, etc.
System.capabilities.screenResolutionY is the height; it can be 600, 768, 720, etc.
So if your resolution is 800x600, "res" will be "800x600".
Create the "resX" to hold the X resolution:
var resX:Number = System.capabilities.screenResolutionX;
You can notice here that it returns a number, not a string; Pay attention to that when using this property.And here we go to a frame based on the screen resolution:
_root.gotoAndStop("res" + resX);
For this to work your frames need to be named like this: "res800", "res1024", "res1152", etc.
You can also use the "switch" statement to select which part of the code to run.
Here is an example:
switch (resX)
{
//if 800x600
case 800:
//run code 1
//leave switch statement
break;
//if 1024x768
case 1024:
//run code 2
break;
//if 1152x864
case 1152:
//run code 3
break;
//if none of the above.
default:
//run code 4
break;
}
