Skip to main content
Participating Frequently
April 20, 2007
Answered

Problem with shared objects synchoronization.

  • April 20, 2007
  • 2 replies
  • 400 views
I encountered a small problem with shared objects.
I'm working on a program that creates chat rooms of a fixed size of 30 users. When the 31th user comes, a new room is created.
The idea is that the client first connects to the first room and checks if it's full by connecting to shared objects. If it is full, connection is closed and process is reapeated on a new instance of the application.

I use a function to connect to an instance, which takes as a parameter a number (1 for instance room_1, 2 for room_2, etc). The function itself creates the necessary Netconnection and sharedObject objects.

If a room is full, Netconnections and sharedObjects are closed and function is called again with another number.

I have no problem for connecting to the first room, but after closing the first connection and connecting to the new room, there seem to be some problems with the shared objects (especially, OnSync doesn't seem to execute again after the connection to the shared objects of the new instance).
I was wondering if you had any ideas what could cause this. Is it the use of the same variable names for connecting at two different shared objects?

Here is the function :

function initStreams(room) {

client_nc = new NetConnection();

client_nc.connect("rtmp://192.168.0.4/Elearning/room_"+room);

in_ns = new NetStream(client_nc);
in_ns2 = new NetStream(client_nc);
Replay_video.attachVideo(in_ns);

out_ns = new NetStream(client_nc);
out_ns2 = new NetStream(client_nc);

in_ns.play("my_recorded_stream");

users_name = SharedObject.getRemote("users_name", _root.client_nc.uri, false);
users_name.connect(_root.client_nc);

users_language = SharedObject.getRemote("users_language", _root.client_nc.uri, false);
users_language.connect(_root.client_nc);

users_picture = SharedObject.getRemote("users_picture", _root.client_nc.uri, false);
users_picture.connect(_root.client_nc);

users_finger = SharedObject.getRemote("users_finger", _root.client_nc.uri, false);
users_finger.connect(_root.client_nc);

}

I you need more info, I can post more of the code on the forum.
Any help would be really appreciated
    This topic has been closed for replies.
    Correct answer
    I don't see any onStatus events in the code you posted above. If you're defining the onstatus event outside the function, that's the problem. When you define the shared object, you also need to define it's onStatus event handler.

    Also, you really should wait for the onStatus event of the netConnection before you connect your sharedObjects. If you try to connect the SO before the netConnection is established, the SO will never connect.



    2 replies

    Participating Frequently
    April 23, 2007
    It worked. The problem was that the onsync functions for the shared objects were defined outside the function. I didn't know the onstatus functions were necessary too.

    Thanks for your help.
    Correct answer
    April 20, 2007
    I don't see any onStatus events in the code you posted above. If you're defining the onstatus event outside the function, that's the problem. When you define the shared object, you also need to define it's onStatus event handler.

    Also, you really should wait for the onStatus event of the netConnection before you connect your sharedObjects. If you try to connect the SO before the netConnection is established, the SO will never connect.