来自服务器的AS3回调不起作用

时间:2012-01-26 19:02:25

标签: actionscript-3 flash-media-server

我的代码调用了我的main.acs,然后向所有用户广播消息。当我向所有用户广播我的消息时,bcStopStreaming函数永远不会被调用。

服务器端代码:

application.onConnect = function(client) {
    application.acceptConnection(client);

    client.stopStreaming = function() {
        trace("#stopStreaming# called");
        application.broadcastMsg("bcStopStreaming");
    }

    client.startStreaming = function() {
        trace("#startStreaming# called");
        application.broadcastMsg("bcStreaming");
    }
}

连接按钮:

public function btnConnectHandler(event:MouseEvent):void
{
    nc = new NetConnection();
    nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

    nc.connect("rtmp://"+hostName+"/test");
    nc.client = new Object();

    nc.client.bcStreaming = function(){
        trace("Started Streaming");
    };

    nc.client.bcStopStreaming = function(){
        trace("Stopped Streaming");
    };
}

断开按钮:

public function btnDisconnectHandler(event:MouseEvent):void {
    nc.call("stopStreaming", null);
    nc.close();
}

我得到错误:

Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.NetConnection was unable to invoke callback bcStreaming. error=ReferenceError: Error #1069: Property bcStreaming not found on test and there is no default value.
at test/btnConnectHandler()

1 个答案:

答案 0 :(得分:1)

您的客户端设置不正确。
请停止使用内联函数。

public function btnConnectHandler(event:MouseEvent):void{
    nc = new NetConnection();
    nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

    nc.connect("rtmp://"+hostName+"/test");
    var myClient = new Object()

    myClient.bcStreaming = this.bcStreaming;
    myClient.bcStopStreaming = this.bcStopStreaming;
    nc.client = myClient;
}
public function bcStreaming(){
    trace("Started Streaming");
}

public function bcStopStreaming(){
    trace("Stopped Streaming");
}

nc.client