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.volumeName.text = e.storageVolume.name;
        this.targetVolume = e.storageVolume.rootDirectory;
        this.currentVolumeNativePath = this.targetVolume.nativePath;

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.

8 Responses to A Demonstration of the New Storage Volume APIs in AIR 2

  1. Tom says:

    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?ThanksTom

  2. Rendy says:

    I am getting this prompt for my flex builder 31046: Type was not found or was not a compile-time constant: StorageVolumeChangeEvent.So missing libraries?

  3. kosty says:

    I run into same type of issues while compiling FileTile.mxmlFileTile.mxml(98): Error: Type was not found or was not a compile-time constant: StorageVolumeChangeEvent.In case it might help, I’m using the milestone release build flex_sdk_4.0.0.10485 on Ubuntu Linux.

  4. kosty says:

    I had the similar problem while compiling FileTile sample application.The problem was solved by grabbing the latest nightly build of Gumbo Flex SDK (v4.1.0.14345) from http://opensource.adobe.com/wiki/display/flexsdk/download?build=

  5. Alex says:

    Any method for unmounting the drive from within AIR? Mac pop up an ugly error if you don’t unmount your drive first, and people won’t have access to the to the finder from a kiosk i am working on. Most likely the Kiosk will be on Windows, however would like to have it work on mac just in case.

  6. Phillip Senn says:

    This looks like it’s Flex.

    Can you write the same using JavaScript and HTML?

    • Yes:

      could look like this

      var StorageVolumeInfo = window.runtime.flash.filesystem.StorageVolumeInfo.storageVolumeInfo;
      var USBstorage = new USBstorage();
      StorageVolumeInfo.addEventListener(window.runtime.flash.events.StorageVolumeChangeEvent.STORAGE_VOLUME_MOUNT, onVolumeMount);
      StorageVolumeInfo.addEventListener(window.runtime.flash.events.StorageVolumeChangeEvent.STORAGE_VOLUME_UNMOUNT, onVolumeUnmount);

      I think you should include ” the aircore.swf in your air application to use the window.runtime methods.

  7. mukesh says:

    I created the AIR 2 application in Flash Builder and installed .AIR o/p into USB drive as .exe. When I run the application from USB drive, I want to see the USB information on which application resides. Can you suggest somethng?