AS3 onBWDone error Flash Media Server with Amazon CloudFront

Recently I’ve been working on building a AS3 streaming video player and ran into an error with onBWDone and wanted to share my findings. I am streaming (RTMP) my video files from Amazon CloudFront which uses Adobe’s Flash Media Server to power its streaming distributions.

You may have seen this error before:

Error #1069: Property onBWDone not found on flash.net.NetConnection and there is no default value.

I will describe three different ways you can fix the onBWDone issue. First one is a fast fix:

_netConnection.client = { onBWDone: function():void{ trace("onBWDone") } };

The second version is to create a public function within the same class and make the NetCennection client equal this. Make sure the function is public! Below is the code:

_netConnection.client = this;

public function onBWDone(...rest):void 
{ 
	var p_bw:Number; 
	if (rest.length > 0){
		p_bw = rest[0]; 
	}
	trace("bandwidth = " + p_bw + " Kbps."); 
} 

The server calls the onBWDone() function when it finishes measuring the bandwidth. It takes four arguments. The first argument it returns is the bandwidth measured in Kbps. The second and third arguments are not used. The fourth argument is the latency in milliseconds.

The third code example I will show involves creating a custom class which I called NetConnectionClient. I placed the public function onBWDone and also the onBWCheck function in the class.

The onBWCheck() function is required by native bandwidth detection. It takes an argument, …rest. The function must return a value, even if the value is 0, to indicate to the server that the client has received the data. You can call onBWCheck() multiple times.

_netConnection.client = new NetConnectionClient();

Below is our custom client class

package
{
	public class NetConnectionClient
	{
		public function NetConnectionClient()
		{
		}
		
		public function onBWCheck(...rest):Number 
		{ 
			return 0; 
		} 
		
		public function onBWDone(...rest):void 
		{ 
			var p_bw:Number; 
			if (rest.length > 0){
				p_bw = rest[0]; 
			}
			trace("bandwidth = " + p_bw + " Kbps."); 
		} 
	}
}

If there is interest from viewers, I will show code examples of my finished streaming AS3 video player. Last thing is if you wanted to call your onBWDone to get the client side bandwidth you can use the following code in your application.

_netConnection.call("checkBandwidth", null);

Let me know if this post has helped anyone

4 Responses to “AS3 onBWDone error Flash Media Server with Amazon CloudFront”

  1. hi rob, your post was pole position in gloogle for ‘flex fms Property onBWCheck not found’, and is actually just what I was looking for. I’m switching from a hosted fms enviro to local, and not at all familiar with the server-side scripts yet.

    Thanks and best,
    Greg

  2. Thanks! This really helped me out :)

  3. Hi.
    You saved me a lot of time.
    Thanks.
    found this article by googling: “onBWCheck not found” red5

  4. as3script Says:
    July 18, 2013 at 7:34 am

    Super solution. I love one liner solution. you saved me. Thanks :-)

Leave a Reply