ActionScript® 3.0 Reference for the Adobe® Flash® Platform
Home  |  Show Packages and Classes List |  Packages  |  Classes  |  What's New  |  Index  |  Appendixes
fl.controls 

ProgressBarMode  - AS3 Flash

Packagefl.controls
Classpublic class ProgressBarMode
InheritanceProgressBarMode Inheritance Object

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 9.0.28.0, AIR 1.0

The ProgressBarMode class defines the values for the mode property of the ProgressBar class.

Related API Elements



Public Properties
 PropertyDefined By
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
Public Methods
 MethodDefined By
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
Public Constants
 ConstantDefined By
  EVENT : String = "event"
[static] The component specified by the source property must dispatch progress and complete events.
ProgressBarMode
  MANUAL : String = "manual"
[static] Manually update the status of the ProgressBar component.
ProgressBarMode
  POLLED : String = "polled"
[static] Progress is updated by polling the source.
ProgressBarMode
Constant Detail

EVENT

Constant
public static const EVENT:String = "event"

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 9.0.28.0, AIR 1.0

The component specified by the source property must dispatch progress and complete events. The ProgressBar uses these events to update its status.

Related API Elements


Example  ( How to use this example )

The following example creates ProgressBar, Label and UILoader component instances and displays the loading progress of an image:

import fl.containers.UILoader;
import fl.controls.Label;
import fl.controls.ProgressBar;
import fl.controls.ProgressBarMode;
import fl.events.ComponentEvent;

var url:String = "http://www.helpexamples.com/flash/images/image2.jpg";

var myUILoader:UILoader = new UILoader();
myUILoader.visible = false;
myUILoader.scaleContent = false;
myUILoader.autoLoad = false;
myUILoader.source = url;
myUILoader.addEventListener(ComponentEvent.RESIZE, resizeHandler);
myUILoader.load();

var myProgressBar:ProgressBar = new ProgressBar();
myProgressBar.mode = ProgressBarMode.EVENT;
myProgressBar.indeterminate = false;
myProgressBar.source = myUILoader;
myProgressBar.setSize(320, 12);
myProgressBar.move((stage.stageWidth - myProgressBar.width) / 2, (stage.stageHeight - myProgressBar.height) / 2);
myProgressBar.addEventListener(Event.COMPLETE, completeHandler);
myProgressBar.addEventListener(ProgressEvent.PROGRESS, progressHandler);
addChild(myProgressBar);

var myLabel:Label = new Label();
myLabel.text = "";
myLabel.autoSize = TextFieldAutoSize.LEFT;
myLabel.move(myProgressBar.x, myProgressBar.y + myProgressBar.height);
addChild(myLabel);

function progressHandler(event:ProgressEvent):void {
    trace("progress:", event.bytesLoaded, "of", event.bytesTotal, "bytes");
    myLabel.text = event.bytesLoaded + " of " + event.bytesTotal + " (" + event.currentTarget.percentComplete.toFixed(1) + "%)";
}

function completeHandler(event:Event):void {
    trace("complete:");
    removeChild(myLabel);
    removeChild(myProgressBar);
    myProgressBar.removeEventListener(ProgressEvent.PROGRESS, progressHandler);
    myProgressBar.removeEventListener(Event.COMPLETE, completeHandler);
    addChild(myUILoader);
}

function resizeHandler(event:ComponentEvent):void {
    trace("resize:");
    var myUILdr:UILoader = event.currentTarget as UILoader;
    myUILdr.move((stage.stageWidth - myUILdr.width) / 2, (stage.stageHeight - myUILdr.height) / 2);
    myUILdr.visible = true;
}

MANUAL

Constant 
public static const MANUAL:String = "manual"

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 9.0.28.0, AIR 1.0

Manually update the status of the ProgressBar component. In this mode, you specify the minimum and maximum properties and use the setProgress() method to specify the status.

Related API Elements


Example  ( How to use this example )

The following example creates ProgressBar and Label component instances to display the progress bar's status:

import fl.controls.Label;
import fl.controls.ProgressBar;
import fl.controls.ProgressBarMode;

var myProgressBar:ProgressBar = new ProgressBar();
myProgressBar.indeterminate = false;
myProgressBar.mode = ProgressBarMode.MANUAL;
myProgressBar.maximum = 256;
myProgressBar.setSize(320, 16);
myProgressBar.move(10, 10)
addChild(myProgressBar);

var myLabel:Label = new Label();
myLabel.text = "";
myLabel.autoSize = TextFieldAutoSize.LEFT;
myLabel.move(myProgressBar.x, myProgressBar.y + myProgressBar.height);
addChild(myLabel);

var t:Timer = new Timer(150);
t.addEventListener(TimerEvent.TIMER, timerHandler);
t.start();

function timerHandler(event:TimerEvent):void {
    myProgressBar.setProgress(myProgressBar.value + 1, myProgressBar.maximum);
    if (myProgressBar.percentComplete == 100) {
        myProgressBar.setProgress(0, myProgressBar.maximum);
    }
    myLabel.text = int(myProgressBar.value) + " of " + int(myProgressBar.maximum) + " (" + int(myProgressBar.percentComplete) + "%)";
}

POLLED

Constant 
public static const POLLED:String = "polled"

Language Version: ActionScript 3.0
Product Version: Flash CS3
Runtime Versions: Flash Player 9.0.28.0, AIR 1.0

Progress is updated by polling the source. The source property must specify an object that exposes the bytesLoaded and bytesTotal properties.

Related API Elements


Example  ( How to use this example )

The following example uses the ProgressBar to display the loading progress of an FLV file:

import fl.controls.ProgressBar;
import fl.controls.ProgressBarMode;

var url:String = "http://www.helpexamples.com/flash/video/cuepoints.flv";

var nc:NetConnection = new NetConnection();
nc.connect(null);

var ns:NetStream = new NetStream(nc);
ns.client = {onMetaData:metaDataHandler};
ns.play(url);

var vid:Video = new Video();
vid.attachNetStream(ns);
vid.x = (stage.stageWidth - vid.width) / 2;
vid.y = (stage.stageHeight - vid.height) / 2;
addChild(vid);

var myProgressBar:ProgressBar = new ProgressBar();
myProgressBar.mode = ProgressBarMode.POLLED;
myProgressBar.indeterminate = false;
myProgressBar.source = ns;
myProgressBar.setSize(vid.width, myProgressBar.height);
myProgressBar.move(vid.x, vid.y + vid.height);
addChild(myProgressBar);

function metaDataHandler(meta:Object):void {
    try {
        trace("w:" + meta.width, "h:" + meta.height);
        vid.width = meta.width;
        vid.height = meta.height;
        vid.x = (stage.stageWidth - vid.width) / 2;
        vid.y = (stage.stageHeight - vid.height) / 2;
        myProgressBar.width = vid.width;
        myProgressBar.move(vid.x, vid.y + vid.height);
    } catch (error:*) {
        // 
    }
}