Skip to main content
Inspiring
April 13, 2007
Question

The amazing repeating event!

  • April 13, 2007
  • 5 replies
  • 506 views
Okay, I'm still working on the problem I've been on for three days. I have a call to main.asc and it returns a string. (I only care that it returns, not what.) Through your help, I am successfully calling the routine in main.asc. But something really weird is happening now.

The return function is getting called even when 1) the connection to the FMS is physically broken, and 2) I remove the return statement from the function in main.asc!

Here's the routine (I have removed my debugging statements for clarity.)

private function ConnectionTest ()
{
_root.application.EventDesktop.m_ConnectionTestResult = false;

//Response function for the heartbeat call above
var ESMSIsConnected = function( )
{
_root.application.EventDesktop.m_ConnectionTestResult = true;
}

if (_root.session.flashComm.m_connection == null)
{
_root.application.EventDesktop.m_tries++;
}
else
{
_root.application.EventDesktop.m_tries = 0;
_root.session.flashComm.m_connection.call( "heartbeat" , new ESMSIsConnected());
}
_root.application.EventDesktop.m_ConnectionTestResultID = setInterval(_root.application.EventDesktop.ConnectionTestResult, 2000);
}

In main the heartbeat function looks like this:
Client.prototype.heartbeat = function()
{
//return "HI!";
}

Now, with the return statement commented out I would not expect the ESMSIsConnected function to ever get executed. Not so - it runs the same with or without the return in heartbeat. What's more, when I pull the network cable, I still get ESMSIsConnected executing.

Obviously I'm still missing some critical concept. Can anyone help?
    This topic has been closed for replies.

    5 replies

    NeeeolAuthor
    Inspiring
    April 16, 2007
    Yes. But that interval is turned on and set to fire every five seconds as soon as I create my NetConnection object. The two second interval is to establish a check on the result from the call to the server; I want to check that once, and only once, two seconds after making each call to the server.

    Anyway, one of my colleagues just figured out my problem. It was in the definition of ESMSIsConnected. I changed it to

    var ESMSIsConnected = new Object();
    ESMSIsConnected.onResult = function(returnValue)
    {
    _root.application.EventDesktop.m_ConnectionTestResult = true;
    }

    and put it in ConnectionTest(), and changed the call to the server:

    m_connection.call( "heartbeat" , ESMSIsConnected);

    It works now.

    Thanks for your help.
    April 16, 2007
    _root.application.EventDesktop.m_ConnectionTestResultID = setInterval(_root.application.EventDesktop.ConnectionTestResult, 2000);

    So, you're setting an interval to call _root.application.EventDesktop.ConnectionTestResult every 2 seconds.

    Dont you want the interval to call ConnectionTest() ?
    NeeeolAuthor
    Inspiring
    April 16, 2007
    I only clear the interval for ConnectionTest when I have intentionally closed the NetConnection object. The idea is to detect when the connection drops out, and then to detect when it is available again. It may be that when it drops out I have to switch to attempting a reconnection, and finally failing after some number of tries or a specified timeframe.

    I clear the interval to ConnectionTestResult every time it fires:

    public function ConnectionTestResult ()
    {
    clearInterval(_root.application.EventDesktop.m_ConnectionTestResultID);
    if (_root.application.EventDesktop.m_ConnectionTestResult != true) {
    _root.application.EventDesktop.setTitleBar("Lost heartbeat");
    }
    else
    {
    _root.application.EventDesktop.setTitleBar("ConnectionTestResult returns TRUE");
    }
    }

    but, this is kind of irrelavent since it's interval is reset when the heartbeat call is made. Since that timer is never canceled (as long as the NetConnection object is alive,) it just keeps firing.

    But here's the thing. m_ConnectionTestResult is only set to true when main makes the callback to ESMSIsConnected. Just before the call to main is made,
    m_ConnectionTestResult is set to false. If ESMSIsConnected doesn't execute, m_ConnectionTestResult cannot become true. This makes no sense.

    Here are the two complete functions:

    private function ConnectionTest ()
    {
    _root.application.EventDesktop.m_ConnectionTestResult = false;

    //Response function for the heartbeat call
    var ESMSIsConnected = function( )
    {
    _root.application.EventDesktop.setTitleBar("ESMSIsConnected fired!!!");
    _root.application.EventDesktop.m_ConnectionTestResult = true;
    }

    if (_root.session.flashComm.m_connection == null)
    {
    _root.application.EventDesktop.m_tries++;
    _root.application.EventDesktop.setTitleBar("Lost connection " + _root.application.EventDesktop.m_tries + " failures");
    }
    else
    {
    _root.application.EventDesktop.m_tries = 0;
    _root.session.flashComm.m_connection.call( "heartbeat" , new ESMSIsConnected());
    }
    _root.application.EventDesktop.m_ConnectionTestResultID = setInterval(_root.application.EventDesktop.ConnectionTestResult, 2000);
    }


    public function ConnectionTestResult ()
    {
    clearInterval(_root.application.EventDesktop.m_ConnectionTestResultID);
    if (_root.application.EventDesktop.m_ConnectionTestResult != true) {
    _root.application.EventDesktop.setTitleBar("Lost heartbeat");
    }
    else
    {
    _root.application.EventDesktop.setTitleBar("ConnectionTestResult returns TRUE");
    }
    }
    NeeeolAuthor
    Inspiring
    April 16, 2007
    Okay, I've made some progress (no, it doesn't work yet.) There is some problem with this statement:

    _root.session.flashComm.m_connection.call( "heartbeat" , new _root.application.EventDesktop.ESMSIsConnected("Oops"));

    This does make the call to main.asc. A trace statement inside main proves it. BUT - the returned value is NOT coming from main. It's like ESMSIsConnected is being executed locally, not remotely. Main.heartbeat returns the word "Hi!". But when I run this code I get back the word "Oops". That tells me that the execution is being performed locally, like ESMSIsConnected is being executed directly from .call, not from main.asc.

    I must be defining the return incorrectly. Any thoughts?
    April 15, 2007
    Where in your code are you clearing the interval? I don't see it there.
    April 13, 2007
    Looking at this line:

    _root.application.EventDesktop.m_ConnectionTestResultID = setInterval(_root.application.EventDesktop.ConnectionTestResult, 2000);

    In the rest of your code, _root.application.EventDesktop.ConnectionTestResult is a boolean variable, but you're setting an interval on it like it's a function.

    Actually, it seems the variable is named _root.application.EventDesktop. m_ConnectionTestResult , so I'm not entirely sure why the function is running at all. Is there other code related to what you've posted above that might be calling ConnectionTest();

    NeeeolAuthor
    Inspiring
    April 13, 2007
    I don't think so. The initial code to start this whole process is a single line:

    _root.application.EventDesktop.m_ConnectionTestID = setInterval(_root.application.EventDesktop.ConnectionTest, 5000);

    and of course the reverse:

    clearInterval(_root.application.EventDesktop.m_ConnectionTestID);

    to stop it. But that does point something out to me. When the connection is lost, the object that contains the clearinterval statement doesn't run the code that should clear it. So that explains why it continues.

    I'm really confused as to why the ESMSIsConnected function continues to fire. There's at least two statements that should stop it. What I'm trying to do is what you said you do to keep track of connections. Am I over-complicating this?