Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 413

Programming actionscript 3.0
Table of Contents

Advertisement

Monitoring a file's download progress
As a file downloads from a remote server to the user's computer, the
(
ProgressEvent.PROGRESS
is dispatched, the
progressHandler()
instance on the Stage is updated. The code for the
/**
* While the file is downloading, update the progress bar's status.
*/
private function progressHandler(event:ProgressEvent):void
{
pb.setProgress(event.bytesLoaded, event.bytesTotal);
}
The progress event contains two properties,
update the ProgressBar component on the Stage. This gives the user a sense of how much of
the file has already finished downloading and how much remains. The user can abort the file
transfer at any time by clicking the Cancel button below the progress bar.
If the file is downloaded successfully, the
completeHandler()
downloading and disables the Cancel button. The code for the
is as follows:
/**
* Once the download has completed, change the progress bar's label one
* last time and disable the "Cancel" button since the download is
* already completed.
*/
private function completeHandler(event:Event):void
{
pb.label = "DOWNLOAD COMPLETE";
btn.enabled = false;
}
Cancelling a file download
A user can abort a file transfer and stop any further bytes from being downloaded at any time
by clicking the Cancel button on the Stage. The following excerpt shows the code for
cancelling a download:
/**
* Cancel the current file download.
*/
public function cancelDownload():void
{
fr.cancel();
) is dispatched at regular intervals. Whenever the
method is invoked and the ProgressBar component
complete
method, which notifies the user that the file has completed
progressHandler()
and
bytesLoaded
bytesTotal
event (
Event.COMPLETE
completeHandler()
Example: Uploading and downloading files
event
progress
event
progress
method is as follows:
, which are used to
) invokes the
method
413

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents