Search code examples
javascriptactionscript-3flashactionscriptscreen-resolution

Are the reported values for flash.system.Capabilities.screenResolutionY and flash.system.Capabilities.screenResolutionX ever incorrect?


I have a site where I collect both the Flash screen resolution data using a .swf file and the same data from JavaScript and send it to my servers.

For some users, this data looks wrong - the Flash resolution is very occasionally larger or smaller than the reported screen resolution in the browser.

For example, one user has a 1600x900 resolution screen as reported in the JavaScript, but a screen size of 1366x768 as reported by Flash.

The ActionScript properties I am using are:

  1. flash.system.Capabilities.screenResolutionX
  2. flash.system.Capabilities.screenResolutionY

The JavaScript properties I am using are:

  1. window.screen.width
  2. window.screen.height

Are there any conditions when one would expect these values to be consistently incorrect in either ActionScript or JavaScript?


Solution

  • I imagine the issue lies in the fact that flash player's flash.system.Capabilities.screenResolutionX/Y properties only report the primary monitor's resolution. (as mentioned in the comments on the question by @akmozo)

    From the documentation: (emphasis mine)

    This property does not update with a user's screen resolution and instead only indicates the resolution at the time Flash Player or an Adobe AIR application started. Also, the value only specifies the primary screen.

    In JS (and this may be dependent on browser), window.screen.width/height will report based on the actual monitor the browser window is on.

    So your discrepancies are likely in the scenario that the browser window is NOT on the primary display. (So AS3 reports the primary display, and JS reports the actual display being used)

    If you need to use Flash and get an accurate value, I'd recommend using one of the following techniques:

    1. Use the stage.fullScreenWidth & stage.fullScreenHeight values which should give you the current monitors resolution.

    2. Use ExternalInterface and get the data from JavaScript:

      if(ExternalInterface.available){
          var screenW:int = int(ExternalInterface.call("window.screen.width"));
          var screenH:int = int(ExternalInterface.call("window.screen.height"));
      }