Archive for the ‘air’ Category

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:

Beatport Downloader 1.0 officially launched!

Friday, April 25th, 2008 |

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 and organize your recently purchased tracks with one click. No more incomplete or lost music, easily see the status of all your downloads. Organize your music like never before through the Downloader's folder naming preferences. This feature allows for full control of how you store and search your music library. Install the application by clicking the Install button to the right. If you do not have Adobe® AIR™, it will ask you to install that first. Learn more about Adobe® AIR™ below.

About Beatport:

Beatport is the first authentic digital music store designed to service the evolution of the digital music culture, redefining how DJs and enthusiasts acquire their music. Beatport.com allows users to access the world of club music through secure, legal, hi-speed, high quality downloads in MP3, MP4 and WAV formats on a pay per download basis. With hundreds of labels and thousands of users world wide, Beatport is recognized as the leader for online, electronic dance music.

So, if you're interested, check out the downloader at www.beatportdownloader.com.

Handling Different File Types in Apollo

Monday, June 4th, 2007 |

So, I've finally snagged some time to whip out a post about dealing with different file types with the File API in Apollo AIR.

The contents of a file can be read into a ByteArray and manipulated there. For example if we had a simple text file we could read in its contents to a ByteArray with the following code:

Actionscript:
  1. var bytes:ByteArray = new ByteArray(); // Create our ByteArray that will hold our file data
  2.  
  3. var myFile:File = File.appResourceDirectory; // Create out file object and tell our File Object where to look for the file
  4. myFile = myFile.resolve("mySampleFile.txt"); // Point it to an actual file
  5.  
  6. var fileStream:FileStream = new FileStream(); // Create our file stream
  7. fileStream.open(myFile, FileMode.READ);
  8.  
  9. fileStream.readBytes(bytes, 0, fileStream.bytesAvailable);
  10.  
  11. trace(ObjectUtil.toString(bytes));

You should see something that looks like the following image when you run this code:

If we wanted to out put some of the data in the ByteArray we could add the following:

Actionscript:
  1. for(var i:Number = 0; i <= 9; i++)
  2. {
  3. trace("Byte Data: " + ObjectUtil.toString(bytes[i]));
  4. }

This would jsut output the first 9 items int he ByteArray. So, you'd see something like the following:

I asked myself, well what good is that? We'll lets say the file you were reading was a PNG. You could figure out how to write that file data out to the PNG file format, or you could check out the AS3 libraries that has a PNG and JPEG encoder already.With that said you now have control...hold that, TOTAL control of the file as you read/write the bytes to/from a file.

In my previous posts (Reading a File & Reading a file Asynchronously), the file contents were read into a String variable. This was accomplished with the FileStream readMultiByte() method.

The readMultiByte(length:uint, charSet:String) method takes two (2) parameters:

  1. length: uint - The number of bytes to read from the stream
  2. charSet: String - The String specifying the character set to use to interpret the bytes read from the stream. I'm looking for a nice list of supported character sets, but have yet to find them. I'll let you know when I do. For now we can use the livedoc examples of "shift-jis", "cn-gb" & "iso-8859-1".

We've checked out reading image data and text data, you could extend either of these to accommodate most situations. I'll keep playing and if I run into anything I'll be sure to add to this series.

Reading a file Asynchronously with ActionScript 3

Thursday, May 31st, 2007 |

Sometimes (okay, manytimes) files are large enough that the process of opening and reading its contents may take some time. To solve issues related to the extra time this may take AS3 allows you to open files asynchronously. I'd like to add to the information from the reading files with AS3 post. Here we'll cover the code necessary to open a file asynchronously and read the file contents as they become available.

Because we are now doing something asynchronously, we will be dealing with events. As the file contents are being read The FileStream object broadcasts progress events that we can listen for and respond to. This ensures that when we are reading data when the data is available.

So, onto the code:

Actionscript:
  1. // Imports
  2. import flash.filesystem.FileMode;
  3. import flash.filesystem.FileStream;
  4. import flash.filesystem.File;
  5. import flash.events.ProgressEvent;
  6. import flash.events.Event;
  7.  
  8. // Declare the FileStream and String variables
  9. private var _fileStream:FileStream;
  10. private var _fileContents:String;
  11.  
  12. private function onCreationComplete():void // Fired when the application has been created
  13. {
  14. var myFile:File = File.appResourceDirectory; // Create out file object and tell our File Object where to look for the file
  15. myFile = myFile.resolve("mySampleFile.txt"); // Point it to an actual file
  16.  
  17. _fileStream = new FileStream(); // Create our file stream
  18.  
  19. _fileStream.addEventListener(ProgressEvent.PROGRESS, onFileProgress); // Add our the progress event listener
  20. _fileStream.addEventListener(Event.COMPLETE, onFileComplete); // Add our the complete event listener
  21.  
  22. _fileStream.openAsync(myFile, FileMode.READ); // Call the openAsync() method instead of open()
  23. }
  24.  
  25. private function onFileProgress(p_evt:ProgressEvent):void // Event handler for the PROGRESS Event
  26. {
  27. _fileContents += _fileStream.readMultiByte(_fileStream.bytesAvailable, "iso-8859-1"); // Read the contens of the file and add to the contents variable
  28.  
  29. fileContents_txt.text = _fileContents; // Display the contents. I've created a TextArea on the stage for display
  30. }
  31.  
  32. private function onFileComplete(p_evt:Event):void // Event handler for the COMPLETE event
  33. {
  34. _fileStream.close(); // Clean up and close the file stream
  35. }

As for what all that code does - first off, import the required classes:

Actionscript:
  1. import flash.filesystem.FileMode;
  2. import flash.filesystem.FileStream;
  3. import flash.filesystem.File;
  4. import flash.events.ProgressEvent;
  5. import flash.events.Event;

Then we'll need to create a couple variables. First, the FileStream which we'll use to read our file and second, a String variable that we'll use to display the file contents.

Actionscript:
  1. private var _fileStream:FileStream;
  2. private var _fileContents:String;

Now we'll create an onCreationComplete() method. This method will handle the creationComplete event of the application to get things rolling. Inside the onCreationComplete() method we'll need to create out File object as well as the FileStream object.

Actionscript:
  1. private function onCreationComplete():void // Fired when the application has been created
  2. {
  3. var myFile:File = File.appResourceDirectory;
  4. myFile = myFile.resolve("mySampleFile.txt");
  5.  
  6. _fileStream = new FileStream();
  7. }

Still in the onCreationComplete() method, we'll need to handle those events that will be dispatched while reading the file asynchronously. The events that we will handle are:

  • ProgressEvent.PROGRESS - This will fire as the bytes are read from the file into the buffer.
  • Event.COMPLETE - This will fire when all the bytes of the file have been read into the buffer.
Actionscript:
  1. private function onCreationComplete():void // Fired when the application has been created
  2. {
  3. var myFile:File = File.appResourceDirectory;
  4. myFile = myFile.resolve("mySampleFile.txt");
  5.  
  6. _fileStream = new FileStream();
  7.  
  8. _fileStream.addEventListener(ProgressEvent.PROGRESS, onFileProgress)
  9. _fileStream.addEventListener(Event.COMPLETE, onFileComplete);
  10. }

The final part of the onCreationComplete() method is to open the file asynchronously. Add the following line to the end of the method:

Actionscript:
  1. _fileStream.openAsync(myFile, FileMode.READ);

Now to handle those events and read our file. First, we'll deal with the PROGRESS event. Inside the onFileProgress() event handler method, we read the availableBytes from the file and add it to our String variable. Notice the second parameter of the readMultiByte() method - "iso-859-1". This specifies the content type of the file that we are reading. I'll cover some of the other content types in a later post. So, keep an eye out for that one if you're curious. Finally, we update the TextArea, to show we are actually reading the file.

Actionscript:
  1. private function onFileProgress(p_evt:ProgressEvent):void
  2. {
  3. _fileContents += _fileStream.readMultiByte(_fileStream.bytesAvailable, "iso-8859-1");
  4.  
  5. fileContents_txt.text = _fileContents;
  6. }

We still need to clean up after ourselves, so in the onFileComplete() method, we'll need to close out FileStream object.

Actionscript:
  1. private function onFileComplete(p_evt:Event):void
  2. {
  3. _fileStream.close();
  4. }

A very simple example, and it is still only text that we are reading. Next time I'd like to cover how to read different file types. So, like I said, keep an eye our for that post.

Reading a file with ActionScript 3

Saturday, May 26th, 2007 |

The ALPHA release of Apollo, Adobe's cross-operating system runtime allows for some pretty sweet functionality:

  • Drag-and-drop support
  • Rich clipboard access
  • Desktop and system
    shortcuts

What I was excited about was the File API. The ability to access, read and write to files is something that is completely necessary in a desktop applications, not to mention, exciting to just play with in ActionScript. Its also something that allows for those Web applications that will be ported to desktop applications, to break out of the constraints of the Web (browser security etc.).

I'd like to give a simple example of the File API and get you started on the how's. Its not that difficult, so lets get started. I'll show you the code...then explain.

Simple File Read Example:

Actionscript:
  1. import flash.filesystem.FileMode;
  2. import flash.filesystem.FileStream;
  3. import flash.filesystem.File;
  4.  
  5. var myFile:File = File.appResourceDirectory; // Create out file object and tell our File Object where to look for the file
  6. myFile = myFile.resolve("mySampleFile.txt"); // Point it to an actual file
  7.  
  8. var fileStream:FileStream = new FileStream(); // Create our file stream
  9. fileStream.open(myFile, FileMode.READ);
  10.  
  11. var fileContents:String = fileStream.readUTFBytes(fileStream.bytesAvailable); // Read the contens of the file
  12. fileContents_txt.text = fileContents; // Display the contents. I've created a TextArea on the stage for display
  13.  
  14. fileStream.close(); // Clean up and close the file stream

First, we'll need to import the following classes:

Actionscript:
  1. import flash.filesystem.FileMode;
  2. import flash.filesystem.FileStream;
  3. import flash.filesystem.File;

Next, we'll need to create our File object so we can let our application know where the file we want to read exists. We'll use the file.appResourceDeirectory to locate the file in relation to our application, then the resolve method of the File object myFile to locate the actual file.

Actionscript:
  1. var myFile:File = File.appResourceDirectory;
  2. myFile = myFile.resolve("mySampleFile.txt");

Now we'll need to actually open the file using the FileStream object. So, we create a new FileStream object, then call the open() method and pass it the File object as well as the FileMode of READ.

Actionscript:
  1. var fileStream:FileStream = new FileStream();
  2. fileStream.open(myFile, FileMode.READ);

We have our file open, so lets go ahead and read the contents of the file. The file is a text file, so we'll simple read the file contents into a String variable using the readUTFBytes() method of out FileStream object. Depending on the type of file and the contents of that file, you will want to use a different read method. Like I said, we'll keep it simple for now. The readUTFBytes() method requires the number of bytes to read. We'll pass the bytesAvailable property of the FileStream object for this parameter. The bytesAvailable prooperty, in this case, is the total bytes for the file. Finally set the value returned from the readUTFBytes() call equal to our String variable.

Actionscript:
  1. var fileContents:String = fileStream.readUTFBytes(fileStream.bytesAvailable);

Alright! Now we have our String variable that contains the contents of our text file. From this point you can do anything you want with it. In this example, I've just set the text property of a TextArea to the value of our String variable

There is one final thing to do, and that is clean up. Make sure you call the close() method of the FileStream object once you are done reading the file.

Actionscript:
  1. fileStream.close();

So that is all you need to get started with the File API. There are a few more things that I'd like to go into detail about, so I'll make sure to post about reading file types other than plain text. I'd also like to create an example of opening a file asynchronously, so look for posts on these subjects soon.

Apollo is on Labs - Houston we have blastoff!

Monday, March 19th, 2007 |

….yeah I know geeky. Apollo is now on Labs!

Apollo is a cross-OS runtime that allows developers to leverage their
existing web development skills (Flash, Flex, HTML, Ajax) to build and
deploy desktop RIA’s.

http://labs.adobe.com

The Rest of ApolloCamp

Sunday, March 18th, 2007 |

Well, I tried to get up a post about the rest of the ApolloCamp presos the next morning, but my connection was crap, and the post seems to have been lost, so here goes the rest.

Kevin Hoyt – Nice Presentation on the File API. One huge bonus is the ability to read and write ActionScript object directly. I've played with the file IO stuff a little so this was cool to see.

Daniel Dura – Awesome "cookbook" session lots of good. Quick examples, of the Apollo's windowing etc.

EUI – Gave a presentation on a desktop application they have been working with Ebay on. The cool thing here wasn't really the application, although some of the features of the app (data filtering) were right up there, but the Java Bridge framework that EUI has been working on. Codenamed Artemis, it allows for access to low-level system functions through Java. Think a wii-mote controlled light saber on the big screen. You can learn more at http://artemis.effectiveui.com/.

Finetune – Showed off their media player that they have been working on. Very cool features like recognizing a playlist on someone's site and keeping it playing in the desktop application when you leave that persons site!

I'm sure I've forgotten quite a bit of all the cool stuff that was presented. I do want to give a big thanks to all those involved with ApolloCamp. It was a great event, and I'm sure a ton of work. Good job everyone!

Christian Cantrell HTML & Apollo

Friday, March 16th, 2007 |

Lots of cool stuff with JavaScript and HTML integration. The HTML component, being able to load in both Google and Yahoo maps at the same time. Nice stuff, but it seems to me like it is just asking for spaghetti code. Of course that is up to the code management of the developer. Pretty cool presentation, but not a whole lot of meat as far as what I'm interested in.

Apollo Keynote

Friday, March 16th, 2007 |

Mike Chambers got up and gave a great introduction to the Apollo team and let everyone know about the great swag that was given out to all the attendees:

Adobe really pumped up the swag for Apollo Camp:

  • Flex Builder with charting
  • Apollo CD with goodies and docs
  • Apollo t-shirt
  • Apollo Book

Kevin Lynch dropped in to present a good overview about why Apollo and why Adobe might present the bits and bytes of Apollo early. Adobe revolutionizes how the work engages with ideas and information across multiple platforms (This is a huge push...cross platform) and devices.

  • Client tchnolgies
  • Server technologies
  • Applications

Pretty much the standard pitch about Adobe technolgies, but hey it's Kevin Lynch, he's been doing this for 10 years. One of the big pushes is for PDF, PDF is being released to ISO.

Apollo is trying toenable web to the desktop. There are a couple differenct engines that are inside of Apollo based on what people are trying to create. Mostly what is happening is people are trying to create tools that bring in more desktop functionality into the web space, also includein gthe mobile space.

- Establishing a first class presence for your application.

Desktop Rich Internet Applications (dRIAs) is the direction Adobe is looking.

SWF and HTML - top level to build applications in Apollo.

SWF - AS, FLex, XM, Video, Audio,

HTML - JS, CSS ,XML

Local Fiel access, netowork status, drag and drop, clipboard access, background processin, mutiple window support, custom window crome.

Examples:

  • Companion applicaiton for amazon watchlist
  • Feed reader with HTML, Scriptaclous (Web app running as a desktop app)
  • Flex word processor (Buzzword) desktop companion to web application.
  • PDF Support sample applicaiton - finnancial data applicaiton, PDF support will be supplied via the Acrobat plugin (so if you don't have it you'll need to install it)

Timeline:

  • H1 - 1st 1/2 of the year (labs next week), Moxie Alpha release, creative suite 3
  • H2 - Flex (Moxie), "Phil0" (Apollo - internet TV app), Flash Media Servier

Q&A:

  • No plans to support QuickTime
  • Centralized distribution and installation
  • Installation super smooth and clean
  • Migration from Flex 2 into Moxie...flex team says "Very easy!"
  • Kevin Lynch says "Whats Moxie?" really, someone asked a question about migrating current Flex applications to Moxie and he asked what it was...hehe.
  • Apollo, most likey will not be the name of the product, someone else has taken it. So they are look at another "cool" name, well just have to wait and see what it is I guess.

Apollo notes

Friday, March 16th, 2007 |

So I'm taking notes during the presentation, these are going to be rough...maybe I'll come back to clean them up...maybe not.

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.