fl.controls

# ProgressBarMode - AS3 Flash

Package | fl.controls
Class | public class ProgressBarMode
Inheritance | ProgressBarMode 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

ProgressBar.mode

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | constructor : Object A reference to the class object or constructor function for a given object instance. | Object

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | hasOwnProperty(name:String):Boolean Indicates whether an object has a specified property defined. | Object
|  | isPrototypeOf(theClass:Object):Boolean Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. | Object
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | toLocaleString():String Returns the string representation of this object, formatted according to locale-specific conventions. | Object
|  | toString():String Returns the string representation of the specified object. | Object
|  | valueOf():Object Returns the primitive value of the specified object. | Object

Public Constants

| Constant | Defined 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

ScrollPane complete event
ScrollPane progress event
UILoader complete event
UILoader progress event
LoaderInfo complete event
LoaderInfo progress event
Sound complete event
Sound progress event
FileReference complete event
FileReference progress event
URLLoader complete event
URLLoader progress event
URLStream complete event
URLStream progress event
Example ( How to use this example )
The following example creates ProgressBar, Label and UILoader component instances and displays the loading progress of an image:
Copy

    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

ProgressBar.maximum
ProgressBar.minimum
ProgressBar.setProgress()
Example ( How to use this example )
The following example creates ProgressBar and Label component instances to display the progress bar's status:
Copy

    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

ScrollPane.bytesLoaded
ScrollPane.bytesTotal
UILoader.bytesLoaded
UILoader.bytesTotal
Sound.bytesLoaded
Sound.bytesTotal
NetStream.bytesLoaded
NetStream.bytesTotal
URLLoader.bytesLoaded
URLLoader.bytesTotal
Example ( How to use this example )
The following example uses the ProgressBar to display the loading progress of an FLV file:
Copy

    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:*) {
            //
        }
    }

© 2015 Adobe Systems Incorporated. All rights reserved.
Mon Apr 10 2017, 12:28 PM -07:00