Adobe Air Intro

Introduction to Adobe Air

Oct 2nd in Tools & Tips by Cesare Rocchi

This tutorial will introduce you to Adobe Air, a framework to build rich internet applications. This first introduction will show how to create a simple application using Html/Js technologies.

PG

Author: Cesare Rocchi

Cesare Rocchi is a UI researcher, currently pursuing his PhD in Human Computer Interaction. He began working in Flash, on applications for mobile devices. His focus has recently been revolving around the user experience of rich internet applications, particularly on tabletop devices, with extensive direction towards user centered design. Most recently, Cesare started his own burgeoning company, consulting on user experience and social media design and development, Studio Magnolia.

What is Adobe Air?

Adobe Air is a framework which allows building desktop applications. Adobe Air applications are based on two technologies: Html/Js and Flash. Developers can choose to build desktop application via Html/Js, Flash or Flex. After a brief overview of the architecture, we will build a simple application using Html/Js.

Step 1 - Architecture of an Air application

An Air application is executed by means of a runtime component, which executes the code contained in the air file. As you can see in the figure Adobe provides the runtime component for the three mayor operative systems, Mac OS X, Windows (XP/Vista) and Linux (note: the Linux version is still in beta). The figure might lead to think that the two approaches are exclusive, either you develop in HTML/JS or Flash. Since the air runtime allows "bridging" between Javascript and ActionScript engines, you can call javascript code from an swf, manipulate HTML/DOM via ActionScript, etc.

Step 2 - OS level functionalities

Adobe Air runtime is not simply an integration of HTML/JS and Flash technologies. The runtime provides a set of API which allows air applications to interact with OS functionalities like:

  • File read and write
  • Native Windows/Menus creation and management
  • Retrieval of internet resources

Adobe Air includes also SQLite, a database engine to locally store and retrieve data.

Step 3 - Installation

To repeat the steps described below you need to install the runtime and the sdk (Software Development Kit), which enables you to build air applications.
The runtime can be downloaded from http://www.adobe.com/go/getair. Just run the installer and follow the instructions. The SDK can be downloaded from: http://www.adobe.com/go/getairsdk Unzip the SDK and place the folders in the location you prefer (macosx users will have to mount a .dmg image). Remember the location of the SDK, we will refer to it as SDKPATH. The directory of the SDK should look like this:

Step 4 - Configuration

The SDK has to be configured, otherwise the OS will not find the commands to be executed. In fact, if you open a shell a type adl, your OS will say something like "command not found". This will work only if you move to the bin directory of the SDK folder. Since we want to be able to run build and test commands from every folder we have to configure the SDK. It is important to type correctly the absolute path of the bin directory in the SDK folder.

On a Mac OS X follow this procedure:

  1. Open the Terminal (/Applications/Utilities/Terminal)
  2. Type cd to be sure you are in your home folder
  3. look for a file named .profile. If it does not exist create it
  4. Look for a line similar to this: export PATH=$PATH:/usr/bin
  5. add another line like this: export PATH=$PATH:/airsdk/bin
  6. if the path to the air SDK contains white spaces wrap it with a double quote (e.g. "/my pathtosdk/air")
  7. Close and reopen the terminal. Or type source .profile

On Windows follow these steps:

  1. Right click on My Computer, choose Properties
  2. Select the Advanced Tab and then click the Environment Variables button
  3. Select PATH from the bottom list and add the path to the sdk folder at the end, as in figure.

To test whether the configuration is successful let's open a shell and type the adt command. The result should be the following:

This response technically means that we have provided a wrong number of parameters to the command, but it also means that the SDK has been correctly installed and configured.

Step 5 - Project creation

Let's now create our project folder. We call it myTest and we create two files: myTest.html and myTest.xml.

The xml file is the configuration file, which enables setting up the air application. Open it with your preferred editor and insert the following code.



The first line is a standard header for xml files. The second line starts the definition of our application. The id is the unique identifier of your application. In this case I prefixed that with my domain name. The filename is the name of the executable that we will generate. Name is the name of the application, as seen by the user. The description is a snippet which is shown during the installation to describe the application. Version indicates the version number of your app, 0.1 in our case.
After specifying metadata about the application we go to the definition of the graphics, enclosed in the tag.

Line 10 specifies the root file, that is the file to be loaded in the air application at startup. In this case the myTest.html that we will show later. Title is the string that will appear in the upper part of the window. The systemChrome specifies whether your application has the standard chrome (the one of the hosting OS), or none. Chrome is a set of standard tools which allows manipulating a windows in a desktop environment, namely the title bar, close/resize buttons, borders and the area to grip for resizing.

The background of an Air application can be set to transparent, but this option is valid only if the chrome is set to none. Visible allows to decide whether you application should be displayed when launched. This is useful when the startup takes some time and you don't want to display the graphics to users. The meaning of tags minimizable, maximizable and resizable should be intuitive and should not need explanation.

Now let's look at myTest.html which actually contains our application.

As you can see it is a standard html page, with a head and a body. The head contains a title and the body has a simple div with center-aligned text.

Step 6 - Running the application

Before packing the application as a .air file we will test it to check whether it produces the expected result. The tool we will use id adl, which allows to run our Air applications without installation. Let's open a shell and go to the directory which contains our myTest files (both html and xml). Then type the following command:

	adl myTest.xml

This runs the application with the chrome of the current OS. On a MacOs should look like this.

Your Air application running on MacOsx

On Windows XP the application will appear like this:

Your Air application running on Windows XP

You might doubt that this application works just with html. Let's test javascript. We change the myTest.html file as follows.

With respect to the previous version we added a script tag which contains the definition of a simple javascript function, myfunction(),popping up an alert (lines 4-8). We added a button to the body (line 12). The action associated with the button click is the popme() function. Let's save the file and run it, using the same command from the shell, adl myTest.xml

If we click the button we should see something like the following:

Javascript runnning on Air application

Step 7 - Deploying Air application

Once your application is ready for deployment we can create the .air file, which is the distribution package for Adobe Air applications. This file, which is based on zip compression, contains all the stuff needed to install air applications. An Air application has to be signed with a certificate. For widely distributed applications it is preferable to obtain a certificate from an authority like thawte. Our purpose is just testing, so a self signed certificate is enough. The creation of a certificate can be done via the adt command. Open a shell, move to the project folder, and type this command:

	adt -certificate -cn mycertificate 1024-RSA mycertificatefile.p12 mysecretpass

adt -certificate -cn is simply the syntax required by the command. The following table explains the values provided to the command.

Parameter Value Explanation
mycertificate The name of the certificate
1024-RSA The encryption key of the certificate
mycertificatefile.p12 The file where the certificate is stored
mysecretpass The password which protects your certificate

If you check the project folder you'll find a new file called mycertificate.p12 which is the self-signed certificate we right created. The project folder should now contain three files as in the figure below.

Project folder with self-signed certificate

Now we have all we need to create our .air file. We have to run a pretty long shell command. Don't panic. I'll explain every single word. First let's see it.

adt -package -storetype pkcs12 -keystore mycertificate.p12 AIRHelloWorld.air AIRHelloWorld.xml AIRHelloWorld.html

As above adt -package is the syntax of the command, storetype indicates the the format of the keystore. This is a pretty technical parameter. To be brief, since we generated a certificate according to the pkcs12 format we have to tell it to the compiler. Next we specify the certificate file, via the -keystore parameter. Finally, we provide the name of the resulting .air file, the xml file containing the application settings and the .html entry point file. When we issue this command we will be asked for the password entered during the creation of the certificate ("mysecretpass") in our case. We now have a .air file, which is the distribution format of our application. If we double click it the installation process will start. Installation goes through two simple steps as shown below.

Installation - First Step

Notice that, since we self signed the certificate, the published Identity of the application if UNKNOWN.

Installation - Second Step

During the second step you can specify where to install the application and whether to start it when the installation is finished.

Conclusion

In this tutorial we have introduced the Adobe Air framework and we have built our first Adobe Air application using Html/Js. In the next episodes we will see how to build the same application with Flex and Flash CS3.

  • Subscribe to the NETTUTS RSS Feed for more daily web development tuts and articles.


Related Posts

Check out some more great tutorials and articles that you might like

Enjoy this Post?

Your vote will help us grow this site and provide even more awesomeness

Plus Members

Source Files, Bonus Tutorials and
More for $9 a month for all TUTS+
sites in one subscription.

Join Now

User Comments

( ADD YOURS )
  1. PG

    azerty October 2nd

    great tut !
    I was looking for such an article.
    Can’t wait to read the next one with Flex and Flash CS3 !

    ( Reply )
  2. PG

    Ivan October 2nd

    Can I port my PHP apps with AIR?

    ( Reply )
  3. PG

    James October 2nd

    Absolutely awesome! I had no idea it was so easy!! :D

    ( Reply )
  4. PG

    Tricks October 2nd

    Awesome!

    ( Reply )
  5. PG

    Shane October 2nd

    An interesting introduction to AIR - I had only last night thought about it.

    The functionalities you mention in step 2 might be appealing in certain circumstances, but I still don’t ‘get it’. AIR seems to be the integration of html/js/flash. So what does it offer over and above these technologies?

    ( Reply )
  6. PG

    Sam Parkinson October 2nd

    Just the tutorial I was looking for. Thanks :)

    ( Reply )
  7. PG

    Connor October 2nd

    This is a fantastic tutorial! Great Job!

    ( Reply )
  8. PG

    insic October 2nd

    First application ive made in AIR is based on snook tutorial ‘Christmas in the Air’. and its very nice. Thanks for posting this tutorial.

    ( Reply )
  9. PG

    Tom Sieron October 2nd

    Instead of going with Flash and Flex wouldn’t it be a good idea to dive deeper into AIR possibilities for AJAX apps?

    I mean there are plenty of good websites dedicated strictly to Flex and Flash and a great community of ActionScript developers, but so little tutorials on harnessing the power of AIR in JavaScript based apps.

    Come on guys! Don’t copy what others have been already writing about for the last couple of years! Flash/Flex is a proprietary technology, go with the open standards and give us more JavaScript+AIR goodies.

    ( Reply )
  10. PG

    Lamin Barrow October 2nd

    WOW.. i was not expecting an Adobe Air tut but here it is. I have a huge collection of light weight air applications on my computer for doing various things and i am absolutely pleased with them. Thanks for the introductory tutorial. :)

    ( Reply )
  11. PG

    James October 2nd

    Hmm… Actually yeh I’d also be interested in the benefits of using AIR. Like Shane said above, all it is is the “integration of html/js/flash” …

    ( Reply )
  12. PG

    Mark October 2nd

    @Ivan, no.

    @Shane, the purpose it to move web apps to a desktop setting. You can take something you’d normally put on a website and make it browser-less (in a sense). AIR has the WebKit engine in it (rendering engine used by Safari and Google Chrome).

    Think of it like this: you have a campaign for a major brand and you’re building a cool Flash mini-site. It’s about 300px x 300px and it does some fancy stuff. The website around it is just the medium to get to it. Instead, if you wrap this thing up in AIR, you can have people download it and run it like it’s a program itself, rather than going to a website is a browser.

    ( Reply )
  13. PG

    David Walsh October 2nd

    Thank you for this tutorial. I’m looking to start Air and this will be valuable.

    ( Reply )
  14. PG

    Shane October 2nd

    @Mark - thanks for the explanation. I still don’t really see the point though.

    In this connected world, taking web-based technologies such as html and javascript and wrapping them up into a little app that I can run on my desktop, independent of a web browser, seems a little pointless.

    I do remember the BBC using it for Olympics updates - I found the installation process seamless and the experience quite good.

    Hey - I’m talking myself out of the ‘don’t see the point’ argument :)

    Still not totally convinced though. :)

    ( Reply )
  15. PG

    Aaron Irizarry October 2nd

    Interesting… thanks for starting me off down another rabbit trail :) I look forward to more on this

    ( Reply )
  16. PG

    AdrianMG October 2nd

    Sweet :)

    ( Reply )
  17. PG

    Matt Radel October 2nd

    Great tut…I needed something introductory like this.

    @shane: The lure is that not only can you create an installable application using web based technologies, but you can also use it to connect to the cloud as well. You can work & save files & whatnot locally…think of it as building your own itunes.

    ( Reply )
  18. PG

    Alex October 2nd

    We’ve started developing a number of in house applications on Flex/Air, and so far it’s quite nice. Flex is a great framework (if you take a couple weeks to really understand it before you start) to build an application on.

    We’ve created a number of small automation routines that run on AIR. One of the service my company offers is SCORM compliant e-learning courses. One AIR app will allow you to build and edit the flow/sequencing of a course, and it will output the folder structure for the application, a templated .fla and .swf corresponding to the learning module/activity and the SCORM compliant manifest (a multiple thousand line xml document unique to each course that tells the Learning Management System how to handle the learning modules).

    All in all, it takes about 35 minutes to set up a project, compared to the 10-15 hours it took before we wrote the AIR app. You can’t do that with an online only Flex project.

    ( Reply )
  19. PG

    Andre October 2nd

    Awesome article. I’m looking for practical tutorials for AIR, please do more! :)

    ( Reply )
  20. PG

    Salmen October 2nd

    WOW i have created my first AIR application

    ( Reply )
  21. PG

    Mohammad October 2nd

    Awesome , Thanks.
    Keep up the good work.

    ( Reply )
  22. PG

    Ben Griffiths October 2nd

    Fantastic intro - Air has so much potential, best to get in there while its still relatively early days ;)

    ( Reply )
  23. PG

    Jad Graphics October 2nd

    WoW! This is cool. I think that Adobe Air has tons of potential. I hope to use this someday…

    ( Reply )
  24. PG

    matt October 2nd

    thanks for this!!

    ( Reply )
  25. PG

    Askllora.com October 2nd

    Very nice tut! Adobe has so many different yet related products that it’s hard to keep up. Intros like this really help bring new applications to light.

    ( Reply )
  26. PG

    Atul Kushwah October 3rd

    It so cool!!! does it works with php5 and mysql ?

    ( Reply )
  27. PG

    colinr October 3rd

    Thanks for this intro, AIR looks very interesting. I’d love to see a tutorial on building an AIR app using the SQLite functionality - I maintain a few bespoke database apps in Director and it would be great to move them to AIR.

    ( Reply )
  28. PG

    Windows Themes October 3rd

    Nice introduction, definitely I will use it :)

    ( Reply )
  29. PG

    Jay Salvat October 3rd

    Thanks a lot for this one.

    ( Reply )
  30. PG

    Roshan October 3rd

    Thank you for this informative post.

    Roshan
    Freelance Developer
    http://www.instantshift.com

    ( Reply )
  31. PG

    Ray October 3rd

    This is an excellent tutorial! Definitely bookmarked…

    ( Reply )
  32. PG

    Cesare October 4th

    Thanks everybody for the congratulations!
    It is really encouraging and motivating!

    ( Reply )
  33. PG

    Sniper Wolf October 4th

    Very Nice Post! :D

    ( Reply )
  34. PG

    Ian October 4th

    Just what I needed, I was hoping to start off working with Adobe AIR sometime soon.

    ( Reply )
  35. PG

    John October 7th

    @Ivan: Yes, you can. Just like you can utilize php in flash apps. Mark is incorrect. If you use javascript you can create get/post calls and connect with php scripts. Similar to how you can use XML requests in flash to do the same thing.

    @Mark: Think of possibilities before you shoot someone’s hopes down :)

    ( Reply )
  36. PG

    Taylor Satula October 9th

    *** n00b alert start ***
    So this is like mozilla prisim just much better?
    *** n00b alert end ***

    Loved the article air seemed to be mtn. but now it seems so much easier to do now that i get it.

    ( Reply )
  37. PG

    Husky October 19th

    If anybody is looking for a reason why use AIR, think about an app for sales force automation. A sales guy is on the road and needs to punch in a few lines about his daily appointments / sales / whatever in the corporate CRM tool. Then he gets to the office at the end of the week and all the files in the local DB synch with the company server. If this is not possible with this technology, then somebody please tell me I am missing the point…

    Cheers.

    ( Reply )
  38. PG

    Buzu October 20th

    Great tutorial, tough AIR is not a framework to build RIAs. It’s a framework to build desktop apps by using internet technologies. It has also its own database system integrated, and its capabilities go beyond the browser. Its the nest big thing for web developers since ajax.

    ( Reply )
  39. PG

    Buzu October 20th

    nest? I mean next…

    ( Reply )
  40. PG

    Surendra Gurjar October 24th

    AIR is a exiting framework I am enjoying it…..

    ( Reply )
  41. PG

    alleyes November 19th

    this seems very promising I will follow you closely.
    Air and flex are very popular and don’t seem to be getting enough attention so I’m sure such tutorials will be very popular.

    Thnkx

    ( Reply )
  42. PG

    kareem November 23rd

    this is wonderful tutorial i will put acopy of this lesson on
    my site here
    http://www.as7ap4you.com

    ( Reply )
  43. PG

    Abethebabe December 6th

    Nice tutorial, when I was installing it on my vista though I had to direct it to the \bin folder

    ( Reply )
  44. PG

    Joao Clerigo December 10th

    Great! Can you make the source files available?

    ( Reply )
  45. PG

    Jash Sayani December 17th

    Great one.

    I have just purchased a signed certificate from Thawte. Could you please help me with signing my application with the new certificate. You have used the pcks12 format in the example, but what format does Thawte use?

    Just reply to my comment with the application signing command. Thanks.

    ( Reply )
  46. PG

    Web Hosting Reviews January 13th

    Thanks for the information

    ( Reply )
  47. PG

    darki777 February 23rd

    Hi, thank you for this great tutorial. I have a question, is it possible to add js files? Like myjsfile.js ???

    Greetings,
    darki

    ( Reply )
  48. PG

    Dilip Maddi March 8th

    Good Start
    Found a small problem while working

    adt -certificate -cn mycertificate 1024-RSA mycertificatefile.p12 mysecretpass

    adt -package -storetype pkcs12 -keystore mycertificate.p12 AIRHelloWorld.air AIRHelloWorld.xml AIRHelloWorld.html

    for the second command to work properly the first command should have the file name as mycertificate.p12 instead of mycertificatefile.p12 i.e.
    adt -certificate -cn mycertificate 1024-RSA mycertificate.p12 mysecretpass

    ( Reply )
  49. PG

    Mubbashir March 17th

    Great post!!!

    I just have a little question: Why do I required to have a Internet connection to package the app?
    When i issued the packaging command i got “Could not generate timestamp: timestamp.geotrust.com”

    ( Reply )
  50. PG

    huwaw69 April 23rd

    this is a really great application for those who will become professionals soon…

    ( Reply )
  51. PG

    Simon April 25th

    @Ivan & @Mark

    I guess you can still use PHP for server-side processing, it just means you have to convert your application to an AJAX driven application.

    ( Reply )
  52. PG

    CgBaran Tuts May 6th

    Nice introduction Thanks

    ( Reply )
  1. Arrow
    Gravatar

    Your Name
    May 6th