Skip to main content
Participant
April 18, 2007
Question

Synchronizing Shared Objects

  • April 18, 2007
  • 1 reply
  • 244 views
// Server side
application.onAppStart = function()
{
// ... code here
application.users_so = SharedObject.get("users_so", false);
// ... more code here
}

application.onConnect = function(newClient, userID)
{
// client object properties being setup, etc
application.users_so.setProperty(userID, newClient);
// ... more code
application.acceptConnection(newClient);
}

// Client side
nc.connect(rtmpURL, userID);
users_so = SharedObject.getRemote("users_so", nc.uri, false);
users_so.connect(nc);

When I call the above on the client side I should receive a copy of all users that are stored in the server's shared object indexable by users_so.data[userID] correct?

on the server side I perform the following:

application.acceptConnection(newClient);
newClient.call("updateStatus", null, userID);

on the client side the updateStatus method looks like this:
nc.syncQuestions = function(userID:String)
{

trace("--> "+users_so.data[userID]+" <--");

}; (is the ';' necessary?!?)

this prints: --> undefined <--

WHY?!? 😞 --> is this because of a race condition between the nc.connect() and the users_so.connect() ??

NOTE: My problem seems to arise when I try to re-connect (i.e. connect w/ client, close client, re-open client)

Cheers
    This topic has been closed for replies.

    1 reply

    April 18, 2007
    I have the feeling it's a timing problem because you're not waiting for the onStatus event from the netconnection before you connect the shared object.

    Try adding an onStatus handler to your netconnection, and wait for a code of "NetConnection.Connect.Success". Then connect your shared object.