AIR 2.0 ENHANCEMENTS OVERVIEW
165
<s:Label id="console" x="74" y="2"/>
Increased Maximum Size of NativeWindow
NativeWindow maximum window size has been increased from 2880x2880 pixels in AIR 1.5.2 to
4095x4095 pixels in AIR 2.0. This feature is useful and will allow using AIR on bigger screens. For
example, now that AIR is capable of registering multi-touch user gestures, you can create AIR applications
that will run on large touchscreens. To test the feature, create a large application and set the width and
height to the dimensions. We would like to note that deploying the AIR application on a device that is
smaller than the size you provided will set the size to the maximum possible size.
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
width="4095" height="4095" />
Platform Awareness–Related APIs
One of the key elements in AIR 2.0 is moving toward an SDK that better ties into the operation system and
gives your application more control. Additionally, the new AIR 2.0 contains platform awareness in which
the code base is more adaptable to constant changes in a device. This means that the program knows the
user’s system capabilities and tracks changes in the user’s environment.
Mass storage: API that allows device detection so you can access networks and storage
devices and recognize changes.
Multi touchscreen: AIR 2.0 adds the ability to recognize multi-touch gestures, one of the most
important milestones in building a mobile application.
Mass Storage Device Detection
An element missing from previous versions of AIR was the ability to access and detect mass storage
changes. In AIR 2.0, you can detect and access the device’s mass storage. There are two classes that
enable you to do so:
flash.filesystem.StorageVolumeInfo: StorageVolumeInfo is a singleton manager that keeps
track of changes to the mass storage devices. Upon changes, StorageVolumeChangeEvent
gets dispatched. There are two types of events: storageVolumeMount and
storageVolumeUnmount.
flash.filesystem.StorageVolume: The StorageVolume class holds information regarding the
properties of the mass storage volume.
Using the new API, you can query the name, label, root directory, and file system type of a volume.
Additionally, it is possible to determine whether a volume is writable or removable. The following
application will display the existing storage devices available, as well as add and remove mass storage
devices in case you add a new device or remove a device such as a USB key.
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
CHAPTER 5
166
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="creationCompleteHandler()">
<fx:Script>
<![CDATA[
import flash.events.StorageVolumeChangeEvent;
import mx.collections.ArrayCollection;
[Bindable]
private var storageCollection:ArrayCollection = new ArrayCollection();
protected function creationCompleteHandler():void
{
var storageVolumes:Vector.<StorageVolume> =
StorageVolumeInfo.storageVolumeInfo.getStorageVolumes();
var length:int = storageVolumes.length;
addEventListeners();
for (var i:int = 0; i < length; i++)
{
addItem( storageVolumes[i] );
}
}
private function addEventListeners():void
{
StorageVolumeInfo.storageVolumeInfo.addEventListener
(StorageVolumeChangeEvent.STORAGE_VOLUME_MOUNT,
function (event:StorageVolumeChangeEvent):void
{
addItem(event.storageVolume);
});
StorageVolumeInfo.storageVolumeInfo.addEventListener
(StorageVolumeChangeEvent.STORAGE_VOLUME_UNMOUNT,
function (event:StorageVolumeChangeEvent):void
{
var nativePath:String = event.rootDirectory.nativePath;
removeItemByNativePath( nativePath );
});
}
private function addItem( storageVolume:StorageVolume ):void
{
var object:Object = new Object();
object = new Object();
object.name = storageVolume.name;
object.icon = storageVolume.rootDirectory.icon.bitmaps[2];
object.nativePath = storageVolume.rootDirectory.nativePath;
object.isWritable = storageVolume.isWritable;
object.isRemovable = storageVolume.isRemovable;
AIR 2.0 ENHANCEMENTS OVERVIEW
167
storageCollection.addItem( object );
}
private function removeItemByNativePath( nativePath:String ):void
{
var len:Number = this.storageCollection.length;
var object:Object;
for ( var i:int=0; i<len; i++ )
{
object = this.storageCollection.getItemAt( i );
if ( object.nativePath == nativePath )
{
this.storageCollection.removeItemAt( i );
break;
}
}
}
]]>
</fx:Script>
<s:List x="87" y="28"
skinClass="components.DataList"
dataProvider="{storageCollection}"/>
</s:WindowedApplication>
Once you attach a USB drive, the volume will be added automatically to the list. After you remove the USB
drive, it will be removed from the list (see Figure 5-9).
Figure 5-9. Mass Storage Detection Device application
Multi-touch Functionality
Multi-touch is one of the most exciting features in AIR 2. The API is matching the Flash Player 10.1, which
will used by mobile devices. Although most of the devices don’t support multi-touch user gestures, the

Get AdvancED Flex 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.