Archive for October, 2007

Badge Install Updates Current and Future

As I’ve mentioned before, install badges are a great way to get your AIR-based application and AIR itself installed on a users machine with minimal hassle. The feature is being used extensively by eBay, AOL, and others to distribute their applications.

If you’re using the install badge, please update to the latest version. You can download it here. This version addresses a cross-site scripting vulnerability in the version previously posted to labs, as described in the FAQ.

We’re also planning some significant improvements to this feature for 1.0. I’ll fill you in when details are available.

AIR Installer Logging

Starting with the beta 2 release, the AIR installers for both AIR itself and for applications can be configured to log actions taken during install. This is not an officially supported feature and we don’t make any promises that the log file format won’t change, or even that this won’t be removed entirely. Nonetheless, you may find it useful.

To enabling logging, simply create a file named either “.airinstall.log” (for the AIR installer) or “.airappinstall.log” (for application install) in your home directory. If this file is present when the installer starts then the log will be written to it (overwriting any previous contents). This works on both Windows and Mac OS. Turn turn logging back off, remove the files.

If you encounter installation-related problems with beta 2 I recommend turning logging on. Even if you’re not up to reading the contents yourself it’ll be a great help to us to include them with any bug reports.

Async APIs and Anonymous Functions

ActionScript has a nifty feature called anonymous functions that is often handy when working with asynchronous APIs. Here’s how it works:

var t:Timer = new Timer( 0 );
var message:String = “Hello, World!”;
t.addEventListener( TimerEvent.TIMER_COMPLETE, function( evt:Event ):void { trace( message ); });

Here, function creates a new, anonymous function taking one argument (an event) and with the body specified inline. I don’t recommend using this technique for long event handler functions; those are usually easier to write as callback functions. But this is a great technique to use when your callback function is short. Replacing a whole set of short callback functions with anonymous functions is a great code cleanup.

Note in the example above that the function body is able to reference message, which is a variable that was defined back in the code that created this function. Creating an anonymous function creates a closure that captures the in-scope variables visible where the function is defined and makes them available when the function executes. This saves you the trouble of littering your class with member variables that exist just to remember stuff until an event handler gets called. Another great code cleanup.

This wraps it up for the basic techniques for asynchronous programming. Next we’ll start in on more advanced topics.

DDJ AIR Article

[I updated this article on Oct 11 to include a link to the online version of the article. --Oliver]

There’s an article on Adobe AIR in the latest (November) issue of Dr. Dobb’s Journal by yours truly. It’s an introduction to AIR, and I think you’ll find it worthwhile reading if you’re looking for an overview. But then, I’m biased.