Skip to main content

Air scare crunch

Fun with HTML, JavaScript and Adobe Air

I've been tracking Adobe Air for a while now, since it was called Apollo in fact, and earlier this year we ran a couple of tests for some of our prototypes. Last Thursday I caught one of Adobe's CS3 roadshows in Sheffield and got an overview of the latest release of Air which brought it back to mind.
For the last few weeks I've been hacking together some sweet AJAX for the interface for our upcoming alpha trial - after running into the same old IE doing it's own sweet thing nightmare I realized that wrapping the whole app up in Air and deploying to the desktop might solve all manor of headaches.

So, easy thought I, simply run my app through the air 'compiler' and ship to all OS's and no longer worry about rogue browser behavior. The current iteration of our app doesn't need any OS interaction, taking as it does only with a Web server, so what could be easier.

Well, its not quite as easy as that. The new version of the Air beta is quite different from the one I was playing with a while back. See, the post load alterations to the 'web page' which is the bread and butter of AJAX have become a security concern, especially when you throw HttpRequest coupled with JSON into the fray. Imagine a suspect JSON payload being eval()ed and doing all manner of nasties - now imagine that running under a framework which can also read and write to you file system - ouch!

So, Adobe have implemented a security model which tries to rectify the issue by running two sandboxes simultaneously:
i) The Classic Sandbox which will run all you good old Web apps but not allow access to the Air API which gives access to the OS etc
ii) The Application Sandbox which gives access to the Air API set but will not stand for any of that AJAX fiddling.



The good news is that you can still have your nice AJAXy interface built the way you like to do it and make use of the API through the use of the 'Sandbox Bridge'.

What all this means is that you can't just take you existing web app and run it through the Air 'compiler' an end up with a desk top app. If you do, your JavaScript won't run and you may see an error such as "Error: Parsing Disallowed". This is because the default mode is to assume the more paranoid (safer) Application Sandbox.

I myself spent hours crawling the web trying to work out why my HTML/CSS/JabaScript app worked perfectly in the browser (IE max-height humour ) but failed to work when compiled to a .air file. All the docs I had were out of date. At first I thought maybe it was something in the JQuery framework I was using - but after building simpler and simpler test models I eventually realized that even an alert box called as a function with 101 JavaScript doesn't work!

Part of the issue was that I abandoned the command line SDK because I was having issues with the path settings - again the result of out of date documentation - and instead added the DreamWeaver Air extension. Now - I'm old school, I started my scripting long before DreamWeaver, GoLive et al came along and so it took me a while to find the 'site' arrangement. Any how, in the end I got my app together and ran it though the Air create extension, which worked smooth enough - but my app didn't work.
It was only after getting a little bash help (I swear I used to know this stuff in the early 90's) and running my tests through the command line SDK that I found the error message "Error: Parsing Disallowed" - which gave me something else to ask The Google. Which lead me eventually to the security model documents and some worked examples!

Now all this sounds a little bit like hard work especially if you have a nice Web app and all you want to do is port it to the desktop to start getting a feel for AIR!

Well, the fact is that it is actually very easy - its just new so there are precious few quick start idiots guides out there.

So if you have been harassing search engines with queries like "Why doesn't my JavaScript work in Air","Air JAVASCRIPT problems" etc, I hope the example below helps you.

So, how is it done?

Well - You create a new HTML file which is the root for your Air app (the file your air XML file calls root) and in this you call your app start page as an IFRAME. Simple as that - well for the base case anyway. This new Root HTML file is the place where you set up the Sandbox bridge and Application Sandbox etc too - but hey you can work up to that.

So by way of a helpful example:

Your App start page:

Lets call this HelloWorld.html



Your Air app root

Lets call this HelloWorldRoot.html




And finally your Application Descriptor File

Lets call this HelloWorld.XML




Download a text file here with all this code in for cutting and pasting.

And thats it - stick these in the same directory at run the Air command line at the XML file - job done!

Now you know how to get your Web app to work on the desk top you can start looking at interacting with the OS through the Air APIs and setting up you Sandbox bridge.

Read about the security model and why here.

See worked examples to help with your next steps here.

Comments

Popular posts from this blog

The Art of the state

A few weeks back I was working with the dev team at WGC on some interface design for our product prototype. We came across a point at which we have to give the user the ability to indicate their desire to save a current state. As we discussed the various ways in which we could visually indicate a 'save' action button, I realized that as a whole the industry has settled on the image of a 'floppy disc' such as this: Now in this day and age the floppy disk is an anachronism - have any of the myspace generation even ever seen one? It is certainly a few years since the average family PC came with a floppy drive as standard equipment and an online life requires little in the way of tangible media. - and yet the iconography persists. The more I thought about this however, the more I came to think that if we needed to provide a user action which is exemplified by an outmoded concept, then maybe we should rethink our interface and indeed application architecture at a deeper lev...

Pro-ams, Prosumers and Innovation

As a team, Technology Research has been paying a great deal of attention to the importance of the end user in the process of innovation and development. We have witnessed over the last couple of years how companies and organizations such as Amazon and Google have benefited by opening up their innovation process to amateur enthusiasts and how others such as Flickr who have made Web Services API's available for experimentation have added value to their product through enhanced capability, flexibility and functionality developed by third parties . And there are many, many other examples. In concept the hacking, adaption or customization of software is not new. The home computers of the early 1980's practically demanded end-user programming, computer Games 'modding' has been around almost as long as computer games have and the definitive open-source example of Linux shows what can become of enthusiast lead development. What is new is the fact that smart organization...

Wake for myPod - consumer electronic bereavement

myPod is dead;-( So, never been a Apple fetishist, the endless PC vs. Mac debate bores the tits off me, much in the same way as the C64 vs. Spectrum arguments with the inherent ridiculous diatribes about the relative merits of PEEKing and POKEing against endless CHR$ing wasted many an hour of my youth. I’ve use both Mac and PC in my time and get on with them both. I have a couple of old Performa’s and an LCIIin my loft (though these are skip rescues rather than purchases), but all my machines are PC based, now mostly XP save for a Linux Tosh Laptop. I gotta say all in all I prefer the nuts and bolts of the PC format and do tend towards thinking Apple lean in a little into the form over function. But still, I was happy with myPod. I bought my wife an iPod for Christmas 2003 and after playing with it for a month bought one for myself, overriding my first digital player choice of the Zen. Although part of this was because I kinda like iTunes and partly because I’d ended up encod...