Flash Media Server Developer Documentation

ActionScript 2.0 native bandwidth detection

You can also use native bandwidth detection from ActionScript 2.0. Just as in ActionScript 3.0, you define functions named onBWCheck() and onBWDone(), and you make a call to NetConnection.call(), passing it the function name checkBandwidth.

Note: Use the BandwidthAS2 sample, BandwidthAS2.as, written in ActionScript 2.0.

Edit Application.xml

 Make sure bandwidth detection is enabled in the Application.xml file for your application:

<BandwidthDetection enabled="true">

Bandwidth detection is enabled by default. You can use an Application.xml file specific to your application or one that applies to a virtual host (see Adobe Flash Media Server Configuration Guide for details).

Write the client code

  1. Define an event handler named onBWCheck() that receives data the server sends:
    NetConnection.prototype.onBWCheck = function(data) {
        return 0; 
    }
    
    

    This handler must return a value, but it can be any value, even 0. The return value lets the server know the data was received.

  2. Define an event handler named onBWDone() that accepts one parameter, the measured bandwidth in kilobytes per second (Kbps):
    NetConnection.prototype.onBWDone = function(bw) {
        trace("bw = " + bw + " Kbps");
    }
    
    

When the server completes its bandwidth detection, it calls onBWDone() and returns the bandwidth figure.

  1. Define an onStatus handler that calls checkBandwidth on the server if the connection is successful:
    NetConnection.prototype.onStatus = function(info) {
        if (info.code == "NetConnection.Connect.Success") {
            this.call("checkBandwidth"); // tell server to start bandwidth detection
        }
    }
    
    
  2. Create a NetConnection object and connect to the server:
    nc = new NetConnection();
    nc.connect("rtmp://host/app");