Identifying Multiple Screens with Adobe AIR

Wednesday, May 7th, 2008

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:

The Amazing Ely has done it again!

Tuesday, March 6th, 2007

Ely Greenfield has posted a flip book example component that he put together for 360Flex.

Ely always puts together some pretty amazing stuff, this is no exception. Check it out on his blog.

Sending XML in Flash

Friday, January 19th, 2007

So you want to send XML in flash? There are some things that you need to watch out for.

ONE: We're working with the XML object.

Actionscript:
  1. var myXML:XML = new XML();
  2. var theXML:String = "";
  3. myXML.parseXML(theXML);

TWO: If you are are expecting a response, use the sendAndLoad() method. You will need to create an XML object to catch the response from your server. The sendAndLoad() method takes 3 parameters:

url - where to send the XML

target - The XML object that receives the downloaded data (this can also be a LoadVars object depending on the data that is returned from the service)

method - GET or POST HTTP protocol. This parameter is optional.

Actionscript:
  1. var responseXML:XML;
  2. myXML.sendAndLoad("http://www.realeyesmedia.com/", responseXML, "POST");

Now what happens if you don't expect a response from the server? Do you use send()? Not if you don't want the page to redirect.

The send() method can GET or POST your XML data to a page, but your Flash piece page is expected to redirect. So, what do you do. Well, just use sendAndLoad() and create a dummy XML object for the 2nd parameter. You won't receive a response, but the XML will be sent to the server just the same.

powered by performancing firefox

Flash Binding Class

Thursday, May 25th, 2006

I whipped up a quick Singlton to progamatically create bindings between two controls:
All you need to do is import the class and then call the addBinding() method on the REBinding Singleton class:
import com.re.data.REBinding;
REBinding.getInstance().addBinding(src_txt, dest_txt, "text", "change");

[Download REBinding.zip - includes sample and class]

J.

Mixing Series Types in Flex 2 Charts

Monday, April 17th, 2006

Becareful when you mix series types in the Flex 2 (BETA 2) Charting Components. All of the documentation says that any chart that extends the CartesianChart can use other series types. This is true but you run into issues beacuse the chart tries to format the series data based on its chart type (makes sense, except we now what to combine series types).

For example if you had an <mx:ColumnChart> with a <mx:ColumnSeries> and <mx:LineSeries> , the chart would result in something like the following:
seriesTypes_column.jpg
Notice how the line doesn't quite line up with the column chart.

If we change the <mx:ColumnChart> to an <mx:CartesianChart>, problem solved. The CartesianChart takes the data for what it is and doesn't try to shoehorn the series in to a specific display. Now check out the ColumnChart, the line series lines up with the column chart.

seriesTypes_cartesian.jpg

Update: It should be becareful what type of chart you use. Basically if you are mixing series types, then use the CartesianChart and you won't run into this problem. Basically what happened below is we tried to force data displayed as a line into a ColumnChart because we used the ColumnChart control. If you use the CartesianChart you won't have this problem. Thank you Ely!

Flex Charting

Thursday, February 23rd, 2006

I've been playing with the Flex 2 Charting components quite a bit latley.

The charting components include Bar, Column, Line, Area, Pie, Plot, HLOC (High/Low/Open/Close) & Candlesitck charts. That is quite a set of charts that allow you to visualize your data right out of the box.

Some of the cool features:

  • You can link up data to your charts and change the data at runtime based on user input, live data feeds etc.
  • Its pretty easty to create drag and drop charts with multiple data series for your chart.
  • Styling your chart is a no-braininer with CSS and inline in the MXML .
  • You can also extend the charts for your own custom charts.

Setting up the data is fairly straight forward using a HTTPService, RemoteObject or WebService tags with a Model tag.

I was working on a sample for label rotation and it turned out to be just a good general sample. So, I've posted it here.

FYI: In the current BETA release there is a little bug with label rotation. You have to embed a font to rotate the labels and when you do that, the ends of the label are cliped off. Adobe knows about the bug and hopefully it will be fixed.

This sample uses an to get an external XML file. Then I break the data into different models for the different charts. I've set up the bar chart to accept a click to update the selected 'company' and update the charts on the bottom (the ComboBox will do the same thing).

Check out the app here (you can right-click to view the source).
View the source here.

10 Minute RSSReader & Flex For Free

Thursday, February 9th, 2006

Macromedia announced the Flex Builder 2 Public BETA so I thought I'd play with it and see what I thought. I'm loving some of the new layout features they have added. It makes the initial layout so easy!Check out the list of features that have been added on the Adobe Labs site.
Free Flex SDK Announcement!

As I was playing, I put this blog reader together in about 10 minutes.


Very simple, but very cool. It will read in an RSS 2.0 feed URL and let you cycle through the articles. You can choose from 3 pre-defined feeds ro enter your own. Oh yeah, this appwill only work locally bacuse it is reading in images and the flash crossdomain policy will get in the way.

View the source here.

Download the source here.

Of course you'll need the updated 8.5 player to view it.

The Flex Builder 2 Public BETA is available on the labs site: labs.macromedia.com

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.