Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 415

Programming actionscript 3.0
Table of Contents

Advertisement

Beginning a file upload
The file upload is initiated when the user clicks on the Upload button on the Stage, which
invokes the
FileUpload.startUpload()
of the FileReference class which causes the operating system to display a system dialog box
prompting the user to select a file to upload to the remote server. The following excerpt shows
the code for the
startUpload()
public function startUpload():void
{
fr.browse();
}
Once the user selects a file to upload, the
causing the
selectHandler()
a new URLRequest object and sets the
constant defined earlier in the code. Finally, the FileReference object uploads the
UPLOAD_URL
selected file to the specified server-side script. The code for the
as follows:
private function selectHandler(event:Event):void
{
var request:URLRequest = new URLRequest();
request.url = UPLOAD_URL;
fr.upload(request);
}
The remaining code in the FileUpload class is the same as the code defined in the
FileDownload class. If a user wishes to terminate the upload at any point, they can click the
Cancel button, which sets the label on the progress bar and stops the file transfer immediately.
The progress bar gets updated whenever the
dispatched. Similarly, once the upload has completed, the progress bar is updated to notify the
user that the file has uploaded successfully. The Cancel button is then disabled until the user
begins a new file transfer.
method. This method calls the
method:
event (
select
method to be invoked. The
URLRequest.url
progress
Example: Uploading and downloading files
browse()
) is dispatched,
Event.SELECT
selectHandler()
property to the value of the
selectHandler()
event (
ProgressEvent.PROGRESS
method
method creates
method is
) is
415

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents