« 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
Comments
Hi Christian,
Thanks for the tutorial, this is an ace new feature!
I've noticed that if you have multiple NativeWindow instances running as part of an Application and listen for the 'StorageVolumeChangeEvent.STORAGE_VOLUME_MOUNT' event then it is fired for each active NativeWindow. Is this a bug or is this the way this system was meant to work? I can manually check for multiple calls by storing references to the drive name I guess but it seems a bit hacky? How would you go about this?
Thanks
Tom
Posted by: Tom at December 11, 2009 6:55 AM
I am getting this prompt for my flex builder 3
1046: Type was not found or was not a compile-time constant: StorageVolumeChangeEvent.
So missing libraries?
Posted by: Rendy at January 5, 2010 9:09 PM
Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy (updated 07-14-2009).