User Guide

Example: Uploading and downloading files 411
/**
* Define reference to the download ProgressBar component.
*/
private var pb:ProgressBar;
/**
* Define reference to the "Cancel" button which will immediately stop
* the current download in progress.
*/
private var btn:Button;
The first variable, DOWNLOAD_URL, contains the path to the file, which gets downloaded onto
the users computer when the user clicks the Download button in the main application file.
The second variable,
fr, is a FileReference object that gets initialized within the
FileDownload.init() method and will handle the downloading of the remote file to the
user’s computer.
The last two variables,
pb and btn, contain references to ProgressBar and Button component
instances on the Stage, which get initialized by the
FileDownload.init() method.
Initializing the FileDownload component
The FileDownload component is initialized by calling the init() method in the
FileDownload class. This method takes two parameters,
pb and btn, which are ProgressBar
and Button component instances, respectively.
The code for the
init() method is as follows:
/**
* Set references to the components, and add listeners for the OPEN,
* PROGRESS, and COMPLETE events.
*/
public function init(pb:ProgressBar, btn:Button):void
{
// Set up the references to the progress bar and cancel button,
// which are passed from the calling script.
this.pb = pb;
this.btn = btn;
fr = new FileReference();
fr.addEventListener(Event.OPEN, openHandler);
fr.addEventListener(ProgressEvent.PROGRESS, progressHandler);
fr.addEventListener(Event.COMPLETE, completeHandler);
}