User Guide
Using the ProgressBar component 993
Creating an application with the ProgressBar
component
The following procedure explains how to add a ProgressBar component to an application
while authoring. In this example, the progress bar is used in event mode. In event mode, the
loading content must emit
progress and complete events that the progress bar uses to
display progress. (These events are emitted by the Loader component. For more information,
see “Loader component” on page 813.)
To create an application with the ProgressBar component in event mode:
1. Drag a ProgressBar component from the Components panel to the Stage.
2. In the Property inspector, do the following:
■ Enter the instance name my_pb.
■ Select Event for the mode parameter.
3. Drag a Loader component from the Components panel to the Stage.
4. In the Property inspector, enter the instance name my_ldr.
5. Select the progress bar on the Stage and, in the Property inspector, enter my_ldr for the
source parameter.
6. Select Frame 1 in the Timeline, open the Actions panel, and enter the following code,
which loads a JPEG file into the Loader component:
/**
Requires:
- Loader component on Stage (instance name: my_ldr)
- ProgressBar component on Stage (instance name: my_pb)
*/
System.security.allowDomain("http://www.helpexamples.com");
var my_ldr:mx.controls.Loader;
var my_pb:mx.controls.ProgressBar;
my_pb.source = my_ldr;
my_ldr.autoLoad = false;
my_ldr.contentPath = "http://www.helpexamples.com/flash/images/image1.jpg";
// when autoLoad is false loading does not start until load() is invoked
my_ldr.load();
In the following example, the progress bar is used in polled mode. In polled mode, the
ProgressBar uses the
getBytesLoaded() and getBytesTotal() methods of the source object
to display its progress.