ActionScript 2.0 Components Language Reference |
|
|
|
| ProgressBar component > Using the ProgressBar component > 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.)
To create an application with the ProgressBar component in event mode:
/**
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.
To create an application with the ProgressBar component in polled mode:my_sound and calls loadSound() to load a sound into the Sound object:
/**
Requires:
- ProgressBar component on Stage (instance name: my_pb)
*/
System.security.allowDomain("http://www.helpexamples.com");
var my_pb:mx.controls.ProgressBar;
my_pb.mode = "polled";
my_pb.source = "my_sound";
var pbListener:Object = new Object();
pbListener.complete = function(evt_obj:Object) {
trace("Sound loaded");
}
my_pb.addEventListener("complete", pbListener);
var my_sound:Sound = new Sound();
my_sound.loadSound("http://www.helpexamples.com/flash/sound/disco.mp3", true);
In the following example, the progress bar is used in manual mode. In manual mode, you must set the maximum, minimum, and indeterminate properties in conjunction with the setProgress() method to display progress. You do not set the source property in manual mode.
To create an application with the ProgressBar component in manual mode:setProgress():
for (var i:Number = 1; i <= total; i++){
// insert code to load file
my_pb.setProgress(i, total);
}
Following are two more examples.
To create an application with the ProgressBar component in manual mode (example 2):
var feed_xml:XML = new XML();
feed_xml.onLoad = function(success:Boolean):Void {
clearInterval(timer);
my_label.text = "XML Loaded";
my_pb.setProgress(feed_xml.getBytesLoaded(), feed_xml.getBytesTotal());
};
function updatePB(local_xml:XML):Void {
my_pb.setProgress(local_xml.getBytesLoaded(), local_xml.getBytesTotal());
}
var timer:Number = setInterval(updatePB, 100, feed_xml);
feed_xml.load("http://www.helpexamples.com/flash/xml/menu.xml");
To create an application with the ProgressBar component in manual mode (example 3):
var img_mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadProgress = function(target_mc:MovieClip, numBytesLoaded:Number, numBytesTotal:Number) {
my_pb.setProgress(numBytesLoaded, numBytesTotal);
};
mclListener.onLoadComplete = function(target_mc:MovieClip) {
//my_pb._visible = false;
};
img_mcl.addListener(mclListener);
this.createEmptyMovieClip("image_mc", 20);
img_mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg", image_mc);
|
NOTE |
You can uncomment the line //my_pb._visible = false; if you want to hide the component after the content loads. |
|
|
|
|