Identifying Multiple Screens with Adobe AIR

Written on May 7, 2008 – 11:52 am | by John |

While working on a presentation about Native Windows & Adobe AIR I ran into the Screen class. The screen object provides information about the display screens available to an application allowing you to position applications/windows on different screens. I say screens and not monitors because of a little caveat that the livedocs have in them:

Note that there is not necessarily a one-to-one correspondance between screens and the physical monitors attached to a computer. For example, two monitors may display the same screen.

I thought I'd have a little fun to get my code fingers back after a week in Cabo San Lucas, and create a little AIR app that identifies each screen. The basics are:

  1. Identify the Screens - I knew I had 2 screens, so that was easy. The screens property is an array of Screen objects, so you can work with as many as the user has.
  2. Create something to identify the windows - I used transparent windows with a label to make things simple.
  3. Then position the new windows on the screens.
Actionscript:
  1. private var _screenOne:Screen;
  2.     private var _screenTwo:Screen;
  3.  
  4.     private function _identScreens( p_event:MouseEvent ):void
  5.     {
  6.         // I know I have 2 screens so I'll just grab those
  7.         _screenOne = Screen.screens[0];
  8.         _screenTwo = Screen.screens[1];
  9.  
  10.         // Now lets identify the screens
  11.         var identOne:IdentWindow = new IdentWindow();
  12.         identOne.title = "Screen One";
  13.         identOne.screenLabel = "1";
  14.  
  15.         // open the irst window and set its position on the first screen
  16.         identOne.open( true );
  17.         identOne.nativeWindow.x = ( _screenOne.bounds.width / 2 ) - ( identOne.width / 2 );
  18.         identOne.nativeWindow.y = ( _screenOne.bounds.height / 2 ) - ( identOne.height / 2 );
  19.  
  20.         var identTwo:IdentWindow = new IdentWindow();
  21.         identTwo.title = "Screen Two"
  22.         identTwo.screenLabel = "2";
  23.  
  24.         // open the second window and set its position on the second screen
  25.         identTwo.open( true );
  26.         identTwo.nativeWindow.x = ( _screenTwo.bounds.right - (  _screenTwo.bounds.width / 2 ) ) - ( identTwo.width / 2 );
  27.         identTwo.nativeWindow.y = ( _screenTwo.bounds.bottom / 2 ) - ( identTwo.height / 2 );
  28. }

Very straight forward and simple, but a fun little exercise.

You can download and install the app (with source) using the badge below:

Please upgrade your Flash Player This is the content that would be shown if the user does not have Flash Player 9.0.115 or higher installed.

Or, download the zip'ed flex archive:

http://john.realeyes.com/wp-content/plugins/downloads-manager/img/icons/winzip.gif download: Identify Screen Sample (4.59KB)
added: 07/05/2008
clicks: 40
description:

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Netvouz
  • description
  • ThisNext
  • MisterWong
  • Wists
  • Facebook
  • StumbleUpon
  • Technorati
  • YahooMyWeb

Related Posts

Put your related posts code here
discussion by DISQUS
Add New Comment
Find entries :

Want to subscribe?

  Subscribe in a reader or,
Subscribe via email:

About me

I'm a senior developer at RealEyes Media, Adobe Certified Instructor and Adobe Certified Professional. Here you'll get my ideas and experience Flex, Flash, ColdFusion and related technologies as well as some generally off the wall stuff.