actionscript-3apache-flexflex3flash-media-server

Reference Error:1069: when trying to call client function from Server FMS(Flash Media Server)


Currently i am working on client and Server side communication, using flex and FMS(Flash Media Server).
I am trying to execute the below program, which checks the connection status every 2 sec, and disconnects if there is no response from client.

Here i am getting an Error:
ReferenceError: Error #1069: Property pings not found on flash.net.NetConnection and there is no default value.

Client Side Code

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[

    import flash.net.NetConnection;
    public var nc:NetConnection;
    public var res:Responder;
    public function netconn():void
    {
        nc = new NetConnection();
        nc.connect("rtmp://127.0.0.1/ChkConn",user.text);
        nc.addEventListener(NetStatusEvent.NET_STATUS, handle);
    }
    public function handle(event:NetStatusEvent):void
    {
        switch(event.info.code)
        {
            case "NetConnection.Connect.Success":
            status.text="Connected";
            break;
            case "NetConnection.Connect.Failed":
            status.text="Failed";
            break;
            case "NetConnection.Connect.Rejected":
            status.text="Rejected";
            break;
            case "NetConnection.Connect.Disconnect":
            trace("coming");
            status.text="Close";
            break;

        }

    }

    public function pings():void
    {
        trace("a ping call from the server has been received");
    }

    public function disconn():void 
  {
nc.close();
nc.addEventListener(NetStatusEvent.NET_STATUS, handle);
status.text="Disconnected";

}



]]> 
</mx:Script>

<mx:Panel x="224" y="41" width="348" height="118" layout="absolute">
    <mx:TextInput x="84" y="24" id="user"/>
    <mx:Button x="253" y="24" label="Connect" click="netconn()"/>
    <mx:Text x="10" y="26" text="Username"/>
</mx:Panel>
<mx:Text x="235" y="207" text="Status:"/>
<mx:Text x="295" y="207" text="Disconnected" id="status"/>
<mx:Button x="295" y="263" label="Disconnect" click="disconn()"/> 

Server-Side Code

 // ActionScript Communications Document
 application.onAppStart=function()
 {
trace("Application Start");
 };
application.onConnect=function(client,name)
{
anyvariable=name;

monitorConnection(client);
if(name!="user1")
{
    application.rejectConnection(client);
    trace(name+" Rejected");
}
else
{
application.acceptConnection(client);
trace(name+" Connect"); 
}

 };

clientPingResponder = function(client) {

this.onResult = function(res) {
    trace("ClientPingResponder.onResult Received: " + res);
    clearInterval(client.cleanupTaskId);
} 

this.onStatus = function(info) {
    trace("ClientPingResponder.onStatus Received: " + info);
}
};
monitorConnection = function(client) {

client.isAlive = function() {
    trace("client.isAlive has been fired");
    client.cleanupTaskId = setInterval(client.dead, 2 * 1000);
    client.call("pings", new clientPingResponder(client));
}

client.dead = function() {
    trace("cleanupTaskId: " + client.cleanupTaskId);
    trace("monitorTaskId: " + client.monitorTaskId);

    clearInterval(client.cleanupTaskId);
    clearInterval(client.monitorTaskId);

    trace("ghost connection has been detected");

    application.disconnect(client);
}

client.monitorTaskId = setInterval(client.isAlive, 7*1000);
trace("detected");
}


application.onDisconnect=function(client)
{
//application.disconnect(client);
trace(anyvariable +" Disconnect");
};

Any Help is Appriciated. Thank you


Solution

  • You need something like.

    nc.client = this;