Skip to main content
Known Participant
February 20, 2013
Answered

nc.call failed

  • February 20, 2013
  • 2 replies
  • 1365 views

I am trying to communicate between client and server using the NetConnection.call method. However, i received a compile error message. 1118: implicit  coercion of a value with a static type object type to a possibly unrelated type flash.net.Responder.

Can somebody please help me fix this?

Thank You in advance

import flash.netConnection;

import flash.events.NetStatusEvent;

var nc:NetConnection = new NetConnection;

nc.connect("rtmfp://fms/exampletest");

nc.addEventListener(NetStatusEvent.NET_STATUS, netHandler);

function netHandler(event:NetStatusEvent)Lvod{

    swicth(event.info.code){

          case "NetConnection.Connect.Success":

          trace("Connected");

         break;

}

}

var test:Object = new Object();

test.onResult = function(arg){

   trace(arg);

};

nc.call("SendMessages", test, "just a test"); ERROR LINE

    This topic has been closed for replies.
    Correct answer

    Sorry guys but it still doesn't appear to be working. I am getting no message in my FMS admin console.The function i believe is called correctly. However, im getting nothing back...

    I show you both my Client-Side and Server-Side code and see if you can identify any errors.

    Client-Side

    var nc:NetConnection = new NetConnection();

    nc.connect("rtmfp://fms/example program");

    nc.addEventListener(NetStatusEvent.NET_STATUS, netHandler);

    function netHandler(Event:NetStatusEvent):void{

    switch(event.info.code):void{

    trace("Connected up");

    break;

    var my_ro:SharedObject = SharedObject.getRemote("myMsg", nc.uri, false);

    my_ro.connect(nc);

    var responder:Responder = new Responder(function(result):void{trace('ok :', result);},

    function (status):void{trace('status :',  status);});

    nc.call("sendMessage", responder, "myTest was called");

    Server-Side

    application.onConnect = function(clientObj){

       //Accept the client

      this.acceptConnection(clientObj);

    }

    client.sendMessage = function(msg){

    trace("calling the test on the server");

    return msg;

    }


    Hi,

    You should call the NetConnection.call() function after receiving NetConnection.Connect.Success. Also, the server side code's syntax is not correct. You must be getting error in the server side application log. You can modify your code like following:

    Client side:

    nc = new NetConnection();

    nc.addEventListener(NetStatusEvent.NET_STATUS, netHandler);

    nc.connect("rtmfp://fms/test");

    function netHandler(event:NetStatusEvent):void {

                                  trace("In onNc "+event.info.code);

                                  if(event.info.code === 'NetConnection.Connect.Success') {

          var responder:Responder = new Responder(function (result):void{trace('ok :', result);},function (status):void{trace('status :',  status);});

          nc.call("sendMessage", responder, "myTest was called");

                                  }

    }

    Server Side:

    application.onConnect = function(clientObj)

    {

              trace("In onConnect");

              this.acceptConnection(clientObj);

              clientObj.sendMessage = sendMessage;

    }

    function sendMessage(msg){

              trace("calling the test on the server");

              return msg;

    }

    2 replies

    Participant
    February 22, 2013

    The problem is that flash thinks Test is just a common object and throws an error when you try to access a Responder object.

    You can change it as below to make it work:

    var test:Responder = new Responder(onResult);

    function onResult(arg:String){

       

        trace(arg);

    }

    OR:

    nc.call("SendMessages", new Responder(onResult), "just a test");

    OR:

    nc.call("SendMessages", null, "just a test");

    flashas3Author
    Known Participant
    February 23, 2013

    Thank you for your replys Chandhan and Apurva. Your answers really helped. To tell you the truth i wasn't even aware of the responder class. I didn't understand why i was keep getting the same error however, i now understand the reasons so thany you.

    flashas3Author
    Known Participant
    February 25, 2013

    Sorry guys but it still doesn't appear to be working. I am getting no message in my FMS admin console.The function i believe is called correctly. However, im getting nothing back...

    I show you both my Client-Side and Server-Side code and see if you can identify any errors.

    Client-Side

    var nc:NetConnection = new NetConnection();

    nc.connect("rtmfp://fms/example program");

    nc.addEventListener(NetStatusEvent.NET_STATUS, netHandler);

    function netHandler(Event:NetStatusEvent):void{

    switch(event.info.code):void{

    trace("Connected up");

    break;

    var my_ro:SharedObject = SharedObject.getRemote("myMsg", nc.uri, false);

    my_ro.connect(nc);

    var responder:Responder = new Responder(function(result):void{trace('ok :', result);},

    function (status):void{trace('status :',  status);});

    nc.call("sendMessage", responder, "myTest was called");

    Server-Side

    application.onConnect = function(clientObj){

       //Accept the client

      this.acceptConnection(clientObj);

    }

    client.sendMessage = function(msg){

    trace("calling the test on the server");

    return msg;

    }

    February 21, 2013

    Hi,

    The prototype of NetConnetion.call() method is

    function call(command:String, responder:Responder, ... arguments):void

    i.e. it takes 2nd parameter as Responder class object. For more details about it, check the following link:

    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/Responder.html

    It is an optional object that is used to handle return values from the server. If you are not returning any thing from the server then you can pass null as the 2nd parameter of call() method.