Nothing ruins a professional presentation faster than an unwelcome Windows error message like the infamous "drive not ready" or "no disk in drive". Flash was created for the web so it doesn't provide any protection against these types of errors.



The good news is that if you're using SWF Studio most of these errors are suppressed for you. However, if you want to call an external application that may try to access a floppy or a CD that isn't loaded, then you're going to need a little more help.

This example shows how to check all possible drives on your system, from A: to Z:, and report on their status. Unless you have a disk in every drive or every drive letter mapped, some of the drives on your system are going to be unavailable.

ssCore.init();
ssDefaults.synchronousCommands = true;
 
var driveList:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var startTime:Number = getTimer();
 
for (var i:Number=0; i<driveList.length; i++)
{
var drive:String = driveList.charAt(i);
var r:Object = ssCore.SysInfo.getDriveLabel({drive:drive});
 
var driveLabel:String = r.result;
 
if (driveLabel == undefined)
driveLabel = r.Error.description;
 
output_txt.text += drive+":" + " " + driveLabel + "\r";
}
 
output_txt.text += "elapsed time: " + String(getTimer()-startTime) + " milliseconds";

A return value of "drive not found" means that a drive is physicially not present and a return value of "device no ready" is usually a CD or DVD drive with no media inserted. Once you know a drive is present, you can call ssCore.Filesys.driveType to find out exactly what type of media you're dealing with.

A: SYSINFO_ERROR_DRIVE_NOT_FOUND
B: SYSINFO_ERROR_DRIVE_NOT_FOUND
C: System
D: Data
E: SYSINFO_ERROR_DEVICE_NOT_READY
F: SYSINFO_ERROR_DEVICE_NOT_READY
G: TIM'S IPOD
H: CRUZER
I: SYSINFO_ERROR_DRIVE_NOT_FOUND
J: SYSINFO_ERROR_DRIVE_NOT_FOUND
K: SYSINFO_ERROR_DRIVE_NOT_FOUND
L: SYSINFO_ERROR_DRIVE_NOT_FOUND
M: SYSINFO_ERROR_DRIVE_NOT_FOUND
N: SYSINFO_ERROR_DRIVE_NOT_FOUND
O: SYSINFO_ERROR_DRIVE_NOT_FOUND
P: SYSINFO_ERROR_DRIVE_NOT_FOUND
Q: SYSINFO_ERROR_DRIVE_NOT_FOUND
R: SYSINFO_ERROR_DRIVE_NOT_FOUND
S: SYSINFO_ERROR_DRIVE_NOT_FOUND
T: SYSINFO_ERROR_DRIVE_NOT_FOUND
U: SYSINFO_ERROR_DRIVE_NOT_FOUND
V: SYSINFO_ERROR_DRIVE_NOT_FOUND
W: SYSINFO_ERROR_DRIVE_NOT_FOUND
X: SYSINFO_ERROR_DRIVE_NOT_FOUND
Y: SYSINFO_ERROR_DRIVE_NOT_FOUND
Z: SYSINFO_ERROR_DRIVE_NOT_FOUND
elapsed time: 77 milliseconds

It took less than 1/10th of a second to check all 26 possible drives on my machine, it was even able to retrieve the labels from my iPod and a USB drive that I had attached as my H: drive.

You can check to see what drives are available and cache that information but, at a cost of less than 3 milliseconds per drive, your users probably won't even notice if you just check before each drive access.

drivenotready.zip 212 KB