Skip to main content
Inspiring
April 11, 2007
Answered

Can't make a Call to main.asc

  • April 11, 2007
  • 5 replies
  • 629 views
Okay, I've got something simple going on but I can't see it. I am trying to add a heartbeat function to main.asc so that my client apps can regularly detect a connection. But I can't get the call to work.

Here's the code from main.asc:

Client.prototype.heartbeat = function()
{
trace("Heartbeat tapped");
return "HI!";
}

Here's the call from the client:

private function ConnectionTest ()
{
var rtn;
rtn= m_connection.call( "heartbeat" );
if (rtn != "HI!") {
Alert.show("Lost heartbeat");
}
}

I'm following other examples in the code that work. I get no response from main and the trace function in main doesn't print in the server admin page, where I expect to see it. Can anyone see what's wrong?
    This topic is closed to new replies. Start a new post to keep the conversation going.
    Correct answer
    Are you defining the netconnection variable in a function? If so, it might be a scope problem. For example:

    function doConnect(){
    var nc = new NetConnection()
    nc.connect(blah, blah)
    }

    If you do it that way, the scope of the var is the function, so it will get garbage collected when the function is done running.

    5 replies

    NeeeolAuthor
    Inspiring
    April 13, 2007
    That's what it was. A colleague and I figured it out late yesterday. I'm passing a reference to the class now.

    Thank you.
    Correct answer
    April 13, 2007
    Are you defining the netconnection variable in a function? If so, it might be a scope problem. For example:

    function doConnect(){
    var nc = new NetConnection()
    nc.connect(blah, blah)
    }

    If you do it that way, the scope of the var is the function, so it will get garbage collected when the function is done running.
    NeeeolAuthor
    Inspiring
    April 12, 2007
    Aaaah!

    Looking more deeply into the way the other functions in our main.asc code that return objects work, I see that that's what we're doing. I missed it.

    Thanks for pointing it out. I knew it was something simple that I missed.

    ************************************************* UPDATE!

    Okay, I added that. But I'm still not getting the calls in to main. I expect to see the trace statement ("Heartbeat tapped") show up in the FMS Admin page each time the function is called. I'm not seeing it. I am interpreting this to mean that the function in main is not being executed (although I could easily be wrong.)

    Besides, I don't think that will work for me anyway. Let me explain. Since the responder only gets executed when main responds, and what I'm expressly looking for is a NON-response (indicating that I've lost the connection) this doesn't do it for me. Right now I'm not getting any response, but I don't know that in my client app. (Event driven programming - ya gotta love it!)

    I know I should be able to get an error when the connection is lost, but through discussions on the forum I understand that the error function is not reliable. Besides, I need to be able to automatically reconnect my app and the audio/video streams that my client was sending. There is no status message that tells when the connection is available again.

    Jay Charles suggested that making a regular call to the server and testing the response was the most reliable method to manage the connection status. That's what I'm attempting to do here.

    There's got to be a better way than this. Maybe Jay could post an example of the calls that he uses to test the connection. Of course, if automatically reconnecting to the app and reestablishing the streams without user intervention is not possible, that knowledge in advance could save all of us a lot of typing! I'm beginning to believe that my requirement is not achievable, that the best I can do is close the app when the connection is lost and make the user reestablish everything. That's going to make a lot of people unhappy.

    Thanks for the help.
    NeeeolAuthor
    Inspiring
    April 12, 2007
    Cancell this message - I found out why my events aren't firing in main.asc. Now I just have to figure out why the connection object is becoming nullified.

    Thanks...
    Inspiring
    April 12, 2007
    Hello :)

    Flash, AS, SSAS .. are asynchronous.

    Try a responder object in your call method (second argument).

    private function ConnectionTest ()
    {
    var responder = {} ;
    responder.onResult = function ( result )
    {
    Alert.show( result);
    }
    m_connection.call( "heartbeat" , responder);
    }

    You can read the documentation of FMS in the PDF
    documentation/flashmediaserver_cs_asd.pdf (in the install directory of
    the server..). The example of the call method is a good example

    EKA+ :)

    Neeeol a écrit :
    > Okay, I've got something simple going on but I can't see it. I am trying to
    > add a heartbeat function to main.asc so that my client apps can regularly
    > detect a connection. But I can't get the call to work.
    >
    > Here's the code from main.asc:
    >
    > Client.prototype.heartbeat = function()
    > {
    > trace("Heartbeat tapped");
    > return "HI!";
    > }
    >
    > Here's the call from the client:
    >
    > private function ConnectionTest ()
    > {
    > var rtn;
    > rtn= m_connection.call( "heartbeat" );
    > if (rtn != "HI!") {
    > Alert.show("Lost heartbeat");
    > }
    > }
    >
    > I'm following other examples in the code that work. I get no response from
    > main and the trace function in main doesn't print in the server admin page,
    > where I expect to see it. Can anyone see what's wrong?
    >
    >