« A Demonstration of the ServerSocket API in AIR 2 | Main | A Demonstration of the NativeProcess APIs in AIR 2 »
November 11, 2009
A Demonstration of the New Storage Volume APIs in AIR 2
Below is a screencast of an application I wrote called FileTile in order to validate the new storage volume APIs in AIR 2:
Detecting the mounting and unmounting of a storage volume in AIR 2 is very easy. The code below shows using the new StorageVolumeInfo class to register for mount and unmount events:
StorageVolumeInfo.storageVolumeInfo.addEventListener(StorageVolumeChangeEvent.STORAGE_VOLUME_MOUNT, onVolumeMount);
StorageVolumeInfo.storageVolumeInfo.addEventListener(StorageVolumeChangeEvent.STORAGE_VOLUME_UNMOUNT, onVolumeUnmount);
Below are the two functions that react to the mounting and unmounting of storage volumes:
private function onVolumeMount(e:StorageVolumeChangeEvent):void
{
if (e.storageVolume.isRemovable)
{
this.nativeWindow.activate();
this.volumeName.text = e.storageVolume.name;
this.targetVolume = e.storageVolume.rootDirectory;
this.currentVolumeNativePath = this.targetVolume.nativePath;
this.start();
}
}
private function onVolumeUnmount(e:StorageVolumeChangeEvent):void
{
if (this.currentVolumeNativePath == e.rootDirectory.nativePath)
{
this.reset();
this.mainView.selectedChild = instructionBox;
}
}
FileTile is a free, open-source application. The code can be downloaded from Google Code.
Posted by cantrell at November 11, 2009 6:52 AM