13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Working with the file system<br />

The storageVolume property of the StorageVolumeChangeEv<strong>en</strong>t object is undefined (null) for an unmounted<br />

volume. However you can access the rootDirectory property of the ev<strong>en</strong>t.<br />

The following code outputs the name and file path of a storage volume wh<strong>en</strong> it is mounted:<br />

StorageVolumeInfo.storageVolumeInfo.addEv<strong>en</strong>tList<strong>en</strong>er(StorageVolumeChangeEv<strong>en</strong>t.STORAGE_VOLUME<br />

_MOUNT, onVolumeMount);<br />

function onVolumeMount(ev<strong>en</strong>t:StorageVolumeChangeEv<strong>en</strong>t):void<br />

{<br />

trace(ev<strong>en</strong>t.storageVolume.name, ev<strong>en</strong>t.rootDirectory.nativePath);<br />

}<br />

The following code outputs the file path of a storage volume wh<strong>en</strong> it is unmounted:<br />

StorageVolumeInfo.storageVolumeInfo.addEv<strong>en</strong>tList<strong>en</strong>er(StorageVolumeChangeEv<strong>en</strong>t.STORAGE_VOLUME<br />

_UNMOUNT, onVolumeUnmount);<br />

function onVolumeUnmount(ev<strong>en</strong>t:StorageVolumeChangeEv<strong>en</strong>t):void<br />

{<br />

trace(ev<strong>en</strong>t.rootDirectory.nativePath);<br />

}<br />

The StorageVolumeInfo.storageVolumeInfo object includes a getStorageVolumes() method. This method<br />

returns a vector of StorageVolume objects corresponding to the curr<strong>en</strong>tly mounted storage volumes. The following<br />

code shows how to list the names and root directories of all mounted storage volumes:<br />

var volumes:Vector. = new Vector.;<br />

volumes = StorageVolumeInfo.storageVolumeInfo.getStorageVolumes();<br />

for (var i:int = 0; i < volumes.l<strong>en</strong>gth; i++)<br />

{<br />

trace(volumes[i].name, volumes[i].rootDirectory.nativePath);<br />

}<br />

Note: On modern Linux distributions, the getStorageVolumes() method returns objects corresponding to physical<br />

devices and network drives mounted at particular locations.<br />

The File.getRootDirectories() method lists the root directories (see “Pointing to the file system root” on<br />

page 673. However, the StorageVolume objects (<strong>en</strong>umerated by the StorageVolumeInfo.getStorageVolumes()<br />

method) provides more information about the storage volumes.<br />

You can use the spaceAvailable property of the rootDirectory property of a StorageVolume object to get the space<br />

available on a storage volume. (See “Determining space available on a volume” on page 679.)<br />

For information about storage volumes on AIR for TV devices, see “Directory view for AIR for TV applications” on<br />

page 670.<br />

More Help topics<br />

StorageVolume<br />

StorageVolumeInfo<br />

Reading and writing files<br />

Adobe AIR 1.0 and later<br />

The FileStream class lets AIR applications read and write to the file system.<br />

Last updated 6/6/2012<br />

687

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!