JavaScript, HTML, AIR - new application architectures #1

As promised, here’s a small example of an application built using JavaScript and HTML, repackaged for the desktop using AIR. The application is a version of the puzzle game Black Box. There’s an online version of the game, an AIR package for download, and a zip with the source and the other game resources.

It’s implemented as a straightforward model/2 architecture: the major components are

  • a game model, which implements the core game domain concepts in JavaScript;
  • an HTML container and JavaScript view/controller, which translates clicks on
    the game board into mesages to the model, and which in turn listens for
    events on the model and responds - generally - by changing classes on the
    DOM nodes which represent the affected game objects;
  • and a css file, in which all the DOM classes are mapped on to graphics and
    other styles -all the graphic rendering of the program is done by CSS.

It was built using Aptana Studio, packaged with the Aptana AIR development plug-in, and uses the JavaScript libraries JQuery and SoundManager2.

So - what did I have to do to get the web version to run under AIR?

Firstly, create an AIR project in studio and copy or import the source files, libraries and other resources.

Secondly, export the project as an AIR package.

And that’s it. As it stands, it’s a pretty simple example of an AIR app - it’s not doing anything with the AIR APIs that are exposed to JavaScript, for example, nor does it have an online component, nor the auto-update facilities that AIR provides. However, all the JavaScript, HTML, CSS runs nicely in a window on the desktop, with the interaction, graphics and even the sound all present and correct (there’s a flash component in SoundManager2, but that’s one of the things the flash-based AIR runtime takes in its stride).

One Response to “JavaScript, HTML, AIR - new application architectures #1”

  • Ben Finn responded:

    Ah, I didn’t know anyone else remembered Black Box - an excellent game. I wrote a Black Box program while at prep school, which was published by Acornsoft for the Acorn Atom in c.1981!

Add your own comment...