back

Under the hood with Adobe Flash Player 10.1 and Adobe AIR 2

by Arno Gourdol, Director of Engineering, Adobe AIR

I am excited to tell you about the latest iteration of Adobe Flash Player and Adobe AIR. For both releases, the engineering teams focused largely on two themes: mobile and performance. In this article, we go under the hood to explore new features, capabilities, and improvements.

Before I go into detail, I want to briefly tell you about the way our teams work together. The AIR and Flash Player teams are only one flight of stairs apart. As you can imagine, they share a lot of code, and both teams work together on features that will benefit both products. Additionally, the Flash Builder and Flash Pro teams sit nearby and we work closely with them to ensure that they deliver a great authoring experience for those who build, debug, and package applications based on the Adobe Flash Platform.

Our organization spends hours and hours agonizing over the small details of a new API, from the name of every single class, property, function, and constant to the way each API is going to behave. We always try to keep two big principles in mind: First, will this API fit in with the rich set of APIs that make up the Flash Platform today — does it follow well established patterns and conventions? Second, will this API be easy to use out of the box — how much can we do with this API in the fewest lines of code.

When we're not agonizing over the details, we spend a lot of time researching what our developer community wants and needs. Many of our engineers spend their free time scouring the forums, reading and responding to comments, and bringing invaluable feedback to the team. We also participate in user group meetings and developer conferences as well as visit customers in their own environment to better understand their challenges and how we can help them succeed.

I hope you'll agree that the latest release of these two runtimes is a major step forward for the Adobe Flash Platform, and more importantly, for designers and developers everywhere. Here's a quick overview of what's new in AIR 2 and Flash Player 10.1.

Performance

A tremendous amount of work went into this iteration of AIR and Flash Player to improve performance.

Modern mobile platforms are designed to deliver desktop-class user experience with dramatically reduced power usage. In addition to optimizations to our Tamarin VM, rendering engine, and media codecs, we are also now fully leveraging GPUs to speed up both the on-screen rendering as well as the audio and video media decoding. Using specialized hardware to do these expensive operations has two benefits: It can result in a better experience with higher frame rate for video while consuming much less power than using the CPU to do the same thing.

Flash Player also includes many optimizations specific to its interaction with web browsers, including instance management to intelligently load and play back SWF content only after it comes into view on the web page as well as pause and resume to ensure that SWF content that is not visible only uses a minimal amount of CPU power.

We have also made a lot of optimizations in our management of memory. Our memory manager and garbage collector have been optimized to consume less memory when running the most common SWF content. We have implemented some new techniques (for example automatic compression of media in memory), and we are much more aggressively releasing temporary memory buffers and media caches.

These optimizations mean that the same SWF content now consumes up to half the memory compared to our previous version.

For AIR apps, we're seeing a reduction in memory usage of up to 30% with some popular apps. This means that AIR apps can be left running for days on end without concern that they will affect the overall performance of your computer.

Those optimizations are critical for Flash Player and AIR to run well on mobile platforms, but many of those improvements also benefit the desktop.

Security

From its inception, AIR was designed to be a secure execution environment for applications.

We spend a lot of time thinking about security. Everyone on the team recently completed an internal training on writing secure code. With every single feature we build, we try to consider every possible security aspect.

We've added some new features to improve the security of your applications. Our networking stack is now fully IPv6 certified. The IPv6 protocol includes stronger support for encrypted transmissions, and as this protocol gets deployed to replace the existing IPv4 protocol, your applications will be ready to take advantage of IPv6 transparently. We have also added support for TLS/SSL sockets, which allow you to use encryption when communicating via sockets to a server.

We have added a Downloaded attribute to File objects that indicates their quarantine status. When users download a file from the Internet, the file is marked with a quarantine bit. This bit can be set by a web browser or FTP application, for example. When this bit is set, the first time users attempt to open the file, they are reminded of the provenance of the file and given a chance to change their mind. Once users agree to open the file, the bit is cleared, and the warning is no longer displayed. Your applications can now take advantage of this additional measure of security by setting this bit when downloading files.

Networking

AIR 2 includes the advanced networking APIs you need to write sophisticated apps, such as mail clients or instant messaging clients. The new APIs give you more information about your networking environments, including information about the networking interfaces available and DNS resolution.

In addition to the previously supported Transmission Control Protocol (TCP), you can now use the lower level Universal Datagram Protocol (UDP). UDP is a more lightweight protocol than TCP, which can perform faster. However, there is a tradeoff: Some of the packets may get lost on the way. Luckily, in several situations, low latency, lossy protocol is what you want (for example for videoconferencing, voiceover IP, or online multiplayer games). Here's how you create a simple UDP socket:

var datagramSocket:DatagramSocket = new DatagramSocket();
datagramSocket.addEventListener(DatagramSocketDataEvent.DATA, dataHandler);

datagramSocket.bind(4040, "127.0.0.1");

While you could previously use TCP sockets to initiate a session and communicate with another server, you can now listen on a socket, which allows your app to be a server. Here's how you start listening on port 8080:

var server:ServerSocket = new ServerSocket();

server.addEventListener(ServerSocketConnectEvent.CONNECT, onConnect);

server.bind(8080);
server.listen();

We also now include support for encrypted socket (TLS/SSL), which allows you to perform encrypted communication with a trusted server. Using an encrypted socket is as simple as the following:

socket = new SecureSocket() instead of socket = new Socket().

The networking APIs in AIR 2 are now much more robust and should enable you to write many more classes of applications that were not possible before.

Desktop integration

While content designed for Flash Player will reliably and consistently play back in any browser that supports Flash Player, AIR enables you to build standalone applications that can integrate with the host operating system, taking advantage of features and functionality available to native applications. For example, AIR already gives you access to the top menu bar and the Dock in Mac OS X as well as the taskbar on Windows. If we only offered a lowest common denominator abstraction of what's available on all the platforms we target, you couldn't build very compelling applications. Instead, we try to give you all the tools you need to take advantage of the features unique to the host platform, while minimizing the work involved, so you can easily build great applications for a variety of operating systems.

With AIR 2, we're introducing new capabilities that enable your application to integrate even more tightly with the operating system.

For example, with a single call you can now ask the system to open a document stored on the local file system, exactly as if a user had double-clicked the document and opened it with the application registered for that file type on the system.

var file:File = File.documentsDirectory.resolvePath("draft.xls");
file.openWithDefaultApplication();

You can now subscribe to events that will be dispatched whenever a file storage media is mounted or unmounted and explore the content of those devices. For example, plugging in a camera, a GPS unit, or a USB key will generate this event:

StorageVolumeInfo.storageVolumeInfo.addEventListener(StorageVolumeChangeEvent.STORAGE_VOLUME_MOUNT, onVolumeMount);
StorageVolumeInfo.storageVolumeInfo.addEventListener(StorageVolumeChangeEvent.STORAGE_VOLUME_UNMOUNT, onVolumeUnmount);

The NativeProcess API allows your application to invoke native code, whether that is another binary installed on the system (for example, a command line tool such as grep) or a native code binary that you package with your application. If you have some legacy native code that you want to be able to reuse, or if you have some code that is performance-critical (for example, to do video encoding), you can now invoke that code from your application. To benefit from this new feature, your application must be packaged as a native installer, which is now supported in AIR 2. A native installer will help users pick the right installer for their system.

Multitouch

Hardware support for touch interaction is becoming more common not just on mobile devices but with desktop and laptop computers as well.

We have added APIs to both AIR 2 and Flash Player 10.1 that enable you to capture multitouch events and gestures and respond to them appropriately, opening up new possibilities for interaction.

For example, using touch you can simplify the user interaction of your application: instead of a set of zoom buttons to navigate a map, use the pinch gestures to zoom in and out.

Printing

The printing APIs have been significantly improved in AIR 2. You now have more control over the settings of a print job. For example, you can choose programmatically the paper size or orientation. In addition, you can now bypass the system print dialog box and offer your own page setup dialog box, or skip it altogether.

In the following example, we request that printing of the current stage starts immediately, bypassing the system dialog boxes, which would be very handy for a point of sale application:

 var printJob:PrintJob = new PrintJob();
 var accepted:Boolean = printJob.start2(null, false);

Global error handler

Global error handling was the most frequently requested feature for Flash Player. We are now making it available to both AIR and Flash Player. You can now write a single handler to process all runtime errors that are not caught by a try/catch statement. This enables you to improve the reliability of your application and makes it easier to debug your application by collecting more reliable information when a problem occurs.

private function onUncaughtError(e:UncaughtErrorEvent):void
{
	// do something useful...
}

loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError);

Globalization

We have added a host of new globalization APIs in AIR 2 to make it easier to convert and display dates, numbers, and currencies while taking into account the user preferences. Those new APIs are available both in AIR 2 and Flash Player 10.1.

With previous versions of the Flash runtime, you could do some simple conversions of date and time, but they were limited and did not always respect the system settings. For example, to display the current date using the short date format, as defined by the system settings and the user preferences, use the following:

var df:DateTimeFormatter = new DateTimeFormatter(LocaleID.DEFAULT, DateTimeStyle.SHORT, DateTimeStyle.NONE);
var shortDate:String = df.format(new Date());

You can also do locale-sensitive string comparisons (collation). For example, did you know that "ch" is sorted as one character between "c" and "d" in Spanish? And did you know that in German, "ö" is after "o," but in Swedish, "ö" is after "z"?

var sortingCollator:Collator = new Collator("fr-FR", CollatorMode.SORTING);
var words:Array = new  Array("Avion" , "aéroplane", "cote", "côte", "coté", "côté");
words.sort(sortingCollator.compare);

See the flash.globalization package for much more.

HTML

To build AIR applications on the desktop, you can choose to use either ActionScript and Flash or JavaScript, HTML, and CSS. In addition to all the core APIs I mentioned earlier, which are available to both ActionScript and JavaScript, we've also made improvements specifically for JavaScript developers. We have updated to a more recent version of WebKit that includes some support for HTML5. One of the most exciting features is the ability to use CSS3 to implement more visually rich applications, including transforms (-webkit-transform* and -webkit-perspective*), gradients, animations (-webkit-transition* and -webkit-animation* properties and the new @keyframes rule), and more. We also now support skinning of scroll bars, which enables you to replace those UI elements with your own version for a more customized appearance.

Text rendering in HTML has been improved with support for the -webkit-column-count and -webkit-column-gap properties.

We now include full support for the <canvas> tag, including the ImageData API: getImageData(), createImageData(), and putImageData().

The version of WebKit in AIR also includes the Nitro JavaScript engine, also known as SquirrelFish Extreme, which can be up to twice as fast as before.

We have also added support for a new JavaScript profiler that can be used to optimize your applications using tools such as Flash Builder or Aptana.

With all these enhancements, you can now build even more compelling AIR apps using the JavaScript, HTML, and CSS tools and techniques also available in modern browsers.

Conclusion

I haven't covered everything that's new in Flash Player 10.1 and AIR 2. We have also added FlashAccess support, peer-assisted networking, HTTP dynamic streaming, file promises, a configurable HTTP idle timeout, local audio encoding, improved accessibility, and more. However, I hope this article gives you a preview of the new versions.

All the tools you need to build AIR 2 apps and to take advantage of the features of Flash Player 10.1 are available as part of Adobe Creative Suite 5. You can also download the free AIR 2 SDK. There is more in-depth information available on Adobe Developer Connection.

Now that you have a better idea of what's available in this release of Flash Player 10.1 and AIR 2, I hope you will be inspired to create awesome new applications and content that will continue to push the envelope of what's possible on the desktop and in the browser. I can't wait to see what you come up with.

‹ Back


Arno Gourdol is the director of engineering for Adobe AIR, Adobe's multiscreen runtime for standalone applications. Previously he led various initiatives within the Creative Suite Business Unit, including XMP, Version Cue and Bridge. Prior to joining Adobe in 2001 he was part of the User Interface team at Apple that conceived, designed and implemented Aqua, the user interface of Mac OS X. Arno is a graduate of the Grenoble University. He lives in San Francisco and enjoys traveling from Abel Tasman to Zanzibar.