BandwidthObserver

Kind of class:class
Inherits from:CoreObject
Version:02/13/07
Author:Aaron Clinger
Classpath:org.casalib.load.BandwidthObserver
File last modified:Monday, 01 December 2008, 13:34:40
Calculates load speeds for individual watched files and remembers the values for comparison with other loads.
Since:
  • Flash Player 7
Example:
  • this.createEmptyMovieClip("loadZone_mc", this.getNextHighestDepth());
    
    var mediaLoad:MediaLoad = new MediaLoad(this.loadZone_mc, "test.jpg");
    var bandwidth:BandwidthObserver = BandwidthObserver.observe(this.mediaLoad);
    
    function onImageLoadProgress(sender:MediaLoad, bytesLoaded:Number, bytesTotal:Number):Void {
        trace("File is loading at " + this.bandwidth.getKBps() + " kBps.");
    }
    
    this.mediaLoad.addEventObserver(this, MediaLoad.EVENT_LOAD_PROGRESS, "onImageLoadProgress");
    this.mediaLoad.start();
Usage note:
  • This class only calculates kiloBYTES per seconds, not the bandwidth speed norm kilobits per second. Bits are not very useful in flash; flash only knows object's size in bytes so kBps is a much more useful number. If you need to find kbps or bits use org.casalib.util.ConversionUtil to convert the values.

Summary


Class methods
Instance methods
Instance methods inherited from CoreObject

Class methods

getAverageKBps

static function getAverageKBps (
) : Number

Returns:
  • Returns the average kBps of all observed loads.

getHighestKBps

static function getHighestKBps (
) : Number

Returns:
  • Returns the highest/fastest kBps of all observed loads.

getLowestKBps

static function getLowestKBps (
) : Number

Returns:
  • Returns the lowest/slowest kBps of all observed loads.

observe

static function observe (

Defines load to observe and calculate the speed of transfer in kBps.
Parameters:
loadItem:
File to observe the request and download speed. Can be any class that inherits from org.casalib.load.base.BytesLoadInterface and dispatches events "onLoadStart", "onLoadProgress" and "onLoadError".
Returns:
Usage note:
  • Loading file should be larger than 30kB and the load should last longer than two seconds to provide a valid value.

Instance methods

destroy

function destroy (
) : Void

getKBps

function getKBps (
) : Number

Returns:
  • returns the kBps of the specific load this instance is observing.

getLoadItem

function getLoadItem (
) : Object

Returns:
  • Returns the bytes load instance being observed.