Flash CS3 Documentation |
|||
| ActionScript 2.0 Components Language Reference > ProgressBar component > ProgressBar.percentComplete | |||
Flash Player 6 (6.0.79.0).
Flash MX 2004.
progressBarInstance.percentComplete
Property (read-only); tells what percentage of the content has been loaded. This value is floored. (The floor is the closest integer value that is less than or equal to the specified value. For example, the number 7.8 becomes 7.) The following formula is used to calculate the percentage:
100 * (value - minimum) / (maximum - minimum)
The following example loads an image into a loader that is associated with a progress bar. A listener for the progress event and another for the complete event both access the percentComplete property to display the percent of loading that has completed.
Drag an instance of the ProgressBar component onto the Stage, and enter the instance name my_pb in the Property inspector. Drag an instance of the Loader component onto the Stage, and enter the instance name my_ldr in the Property inspector. Add the following code to Frame 1 of the timeline:
/**
Requires:
- Loader component instance on Stage (instance name: my_ldr)
- Progress component instance 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.mode = "polled";
my_pb.source = my_ldr;
my_ldr.autoLoad = false;
var pbListener:Object = new Object();
pbListener.progress = function(evt_obj:Object) {
trace("progress = " + my_pb.percentComplete + "%");
}
pbListener.complete = function(evt_obj:Object) {
trace("complete = " + my_pb.percentComplete + "%");
}
my_pb.addEventListener("progress", pbListener);
my_pb.addEventListener("complete", pbListener);
// when autoLoad is false loading does not start until load() is invoked
my_ldr.load("http://www.helpexamples.com/flash/images/image1.jpg");
Flash CS3