PDA

View Full Version : FMS onBWDone return



dColumbus
March 12th, 2009, 08:28 PM
So it's great that we can trace what we get from onBWDone... but how can I return something back to my Flash or Flex application?

I've tried applying a responder but it doesn't seem to be doing anything...



package {

import flash.display.Sprite;
import flash.net.*;
import flash.events.NetStatusEvent;

public class Bandwidth extends Sprite
{
private var nc:NetConnection;

// dColumbus added this
public var res:Responder = new Responder(bwResp);

public function Bandwidth()
{
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nc.client = new Client();
nc.connect("rtmp://fms01.tmc.vispnoc.net/bwcheck");
}

public function netStatusHandler(event:NetStatusEvent):void
{
switch (event.info.code)
{
case "NetConnection.Connect.Success":
// calls bandwidth detection code built in to the server
// no server-side code required
trace("The connection was made successfully");
nc.call("checkBandwidth", res);
break;
case "NetConnection.Connect.Rejected":
trace ("sorry, the connection was rejected");
break;
case "NetConnection.Connect.Failed":
trace("Failed to connect to server.");
break;
}
}

// dColumbus added this
private function bwResp(removeResponse:Object):void
{
trace(removeResponse);
}
}
}


class Client {
public function onBWCheck(... rest):Number {
return 0;
}

public function onBWDone(... rest):Number {
var p_bw:Number;
if (rest.length > 0) p_bw = rest[0];
// do something here
// when the bandwidth check is complete
trace("bandwidth = " + p_bw + " Kbps.");

// dColumbus added this
return p_bw;
}
}