Identifying Multiple Screens with Adobe AIR

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

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: 8
description:

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

Adobe Announces the Open Screen Project

April 30, 2008 – 10:21 pm

Adobe has just announced the Open Screen Project. The Skinny: Restrictions on use of the SWF and FLV/F4V specifications will be removed The device porting layer APIs for Adobe Flash Player will be ...

Beatport Downloader 1.0 officially launched!

April 25, 2008 – 9:32 pm

The Beatport Downloader launched officially on April 22nd. This is an application that the team here at Realeyes built. The official downloader description follows: The Beatport Downloader allows you to download ...

REDBug, Wordpress and Firing up the Grill (Link share)

April 25, 2008 – 9:40 am

It has been a little slower at Realeyes latley so I’ve had time to play a bit. While playing I’ve run into some pretty interesting things over the past week, ...

HOW TO: Delete an XML node using E4X

April 21, 2008 – 11:06 am

While creating a sample application for some class content the other day, I ran into an XML/E4X situation that I'd never encountered before. It is pretty basic - deleting ...

Startin’ ‘em Early!

March 6, 2008 – 12:23 pm

Yeah it's a bad picture taken with an iPhone, but still cool!

Head in the sand

March 2, 2008 – 5:54 pm

Geeze! I feel like my head has been in the sand for the last couple of months. We've been extremely busy at Realeyes with a couple of projects. What's funny ...

Flex and Using Meta Data

January 5, 2008 – 1:04 am

"Metadata is data about data" in the case of Flex it is going to describe our components, classes and their interactions/uses. For example the most familiar metadata tag in Flex ...

RSS Feed Fixed

November 19, 2007 – 10:41 am

My RSS feed was hosed after we updated our DNS and created our sub-domains. It should be fixed now.Powered by ScribeFire.

E4X XML Namespaces

November 6, 2007 – 10:57 pm

For XML that looks like the following response from Yahoo's weather service: [xml] < ?xml version='1.0' encoding='UTF-8'?> http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/* http://weather.yahoo.com/forecast/94089_f.html Yahoo! Weather for Sunnyvale, CA en-us Tue, 06 Nov ...

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.