User Guide
394 Networking and Communication
Working with file upload and download
The FileReference class lets you add the ability to upload and download files between a client
and a server. Users are prompted to select a file to upload or a location for download from a
dialog box (such as the Open dialog box on the Windows operating system).
Each FileReference object that you create with ActionScript refers to a single file on the user’s
hard disk. The object has properties that contain information about the file’s size, type, name,
creation date, and modification date.
You can create an instance of the FileReference class in two ways. You can use the
new
operator, as the following code shows:
import flash.net.FileReference;
var myFileReference:FileReference = new FileReference();
Or you can call the FileReferenceList.browse() method, which opens a dialog box on
the user’s system to prompt the user to select one or more files to upload and then creates an
array of FileReference objects if the user selects one or more files successfully. Each
FileReference object represents a file selected by the user from the dialog box. A FileReference
object does not contain any data in the FileReference properties (such as
name, size, or
modificationDate) until one of the following happens:
■ The FileReference.browse() method or FileReferenceList.browse() method has
been called, and the user has selected a file from the file picker.
■ The FileReference.download() method has been called, and the user has selected a file
from the file picker.
While calls to the
FileReference.browse(), FileReferenceList.browse(), or
FileReference.download() method are executing, most players will continue SWF file
playback.
NOTE
The creator property is supported on the Macintosh only. All other platforms return null.
NOTE
When performing a download, only the FileReference.name property is populated before
the download is complete. After the file has been downloaded, all properties are
available.