User Guide
Example: Uploading and downloading files 409
The FileIO application files are found in the Samples/FileIO folder. The application consists
of the following files:
FileIO application overview
The File IO application contains the user interface that allows a user to upload or download
files using Flash Player. The application first defines a couple of custom components,
FileUpload and FileDownload, which can be found in the
com.example.programmingas3.fileio package. Once each custom component dispatches its
contentComplete event, the component’s init() method is called and passes references to a
ProgressBar and Button component instance, which allow users to see the file’s upload or
download progress or cancel the file transfer in progress.
The relevant code from the FileIO.mxml file is as follows:
<example:FileUpload id="fileUpload"
creationComplete="fileUpload.init(uploadProgress, cancelUpload);" />
<example:FileDownload id="fileDownload"
creationComplete="fileDownload.init(downloadProgress, cancelDownload);"
/>
The following code shows the Upload File panel, which contains a progress bar, and two
buttons. The first button,
startUpload, calls the FileUpload.startUpload() method,
which calls the
FileReference.browse() method. The following excerpt shows the code for
the Upload File panel:
<mx:Panel title="Upload File" paddingTop="10" paddingBottom="10"
paddingLeft="10" paddingRight="10">
<mx:ProgressBar id="uploadProgress" label="" mode="manual" />
<mx:ControlBar horizontalAlign="right">
<mx:Button id="startUpload" label="Upload..."
click="fileUpload.startUpload();" />
<mx:Button id="cancelUpload" label="Cancel"
click="fileUpload.cancelUpload();" enabled="false" />
</mx:ControlBar>
</mx:Panel>
File Description
FileIO.mxml The main application file consisting of the
MXML user interface.
com/example/programmingas3/fileio/
FileDownload.as
A class that includes methods for downloading
files from a server.
com/example/programmingas3/fileio/
FileUpload.as
A class that includes methods for uploading
files to a server.