Welcome, Guest
  • Author Topic: usernames in the remote SharedObject  (Read 1844 times)

    cyb

    • Server what's that
    • *
    • Posts: 10
      • View Profile
      • Email
    usernames in the remote SharedObject
    « on: 03/20/07, 05:25 »
    hello! I'm trying to do a chat without remote components, the problem is I'can't see the usernames memorized in a remote SharedObject. this is the code:

    Code: [Select]
    /////////////////////////////////////////////////////////////////
    _root.idchat=0;
    _root.utente1 = "";
    _root.utente2 = "";
    chat_txt.text="ciao";
    usersonline="";
    //rileva utenti
    att="niente";
    var qualiutenti:LoadVars = new LoadVars();
    qualiutenti.onLoad = function(success){
    att="vediamo";
    if(success){
    _root.utente1 = qualiutenti.utentechat;
    _root.utente2 = qualiutenti.utentechat2;
    _root.idchat=qualiutenti.idchatpriv;
    user_txt.text= _root.utente1;
    } else {
    att = "non va";
    }
    };
    qualiutenti.sendAndLoad("chat.php",qualiutenti,"POST")
    ////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////
    function clicked(){
        // Create a connection Object
    client_nc = new NetConnection();
    // Connect to the application
    client_nc.connect("rtmp:/chatapp", user_txt.text);

    users_so = SharedObject.getRemote("users_so", client_nc.uri, true);
    // connetto lo SharedObject al Flash Communication Server

    users_so.connect(client_nc);

    if (users_so.connect(client_nc)) {
      adv_txt.text="Connection object and URIs are OK. Wait for first onSync.";
    }else {
      adv_txt.text="Can't connect - check URIs and the NetConnection object.";
    }

    users_so.onSync = function() {

    // controlla nel debugger i valori assunti dalle proprietà
    //test = userList

    for ( var i in users_so.data ) {
    //_root.peopleonline.removeAll();
    if ( users_so.data[i] != null ) {

    traccia += users_so.data[i]
    //_root.peopleonline.addItem(users_so.data[i]);
    //usersonline=usersonline+users_so.data[i];
    //chat_txt.text=chat_txt.text+users_so.data[i];

    }
    }
    }
    chat_txt.text=traccia;
    }
    connectbutton.addEventListener("click", clicked);

    chat_txt.text=traccia;
    (this dynamic text is empty efter the click on the connect button,
    I'can see:

    adv_txt.text="Connection object and URIs are OK. Wait for first onSync.";


    and this is the serverside code:

    Code: [Select]
    application.onAppStart = function()
    {
    // recupero lo shared object 'users_so'
    application.users_so = SharedObject.get("users_so", true);

    // inizializzo l'history
    application.history = "";

    // inizializzo la  user ID
    application.nextId = 0;
    }

    application.onConnect = function(newClient, name)
    {

    // nuovo nome del client è uguale allo user inserito nel campo
    newClient.name = name;

    // creo un id univoco per l'utente incrementando l'application.nextId
    newClient.id = "u" + application.nextId++;

    // aggiorno lo   shared object 'users_so' con il nome utente
    application.users_so.setProperty(newClient.name, name);

    // accetto la connessione dell'utente
      application.acceptConnection(newClient);

    // chaimo la funzione 'setHistory,' e le
    // passo la history iniziale

      newClient.call("setHistory", null, application.history);

    // il client utilizza quesat funzione per recuperare i dati
    // dal server che a sua volta li distribuisce agli altri client
    newClient.msgFromClient = function(msg, time) {

    msg = this.name + " [" + time + "] " + ": " + msg + "\n";

    application.history += msg;
    application.users_so.send("msgFromSrvr", msg);

    }

    }

    application.onDisconnect = function(client)
    {
    trace("disconnesso: " + client.name);
    application.users_so.setProperty(client.name, null);
    }

    can you help me to find the mistake??
    (sorry for my english)

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: usernames in the remote SharedObject
    « Reply #1 on: 03/20/07, 08:22 »
    Wait until client_nc is connected (check the onStatus handler) to connect your SO

    Jorge


    cyb

    • Server what's that
    • *
    • Posts: 10
      • View Profile
      • Email
    Re: usernames in the remote SharedObject
    « Reply #2 on: 03/21/07, 03:51 »
    yes, it works!!Thank you very much!!
    bye,cyb

    (this is the code)
    Code: [Select]
    function clicked(){
        // Create a connection Object
    client_nc = new NetConnection();
    // Connect to the application
    client_nc.connect("rtmp:/chatapp", user_txt.text);

    client_nc.onStatus = function(infoObject){
    if (infoObject.code == "NetConnection.Connect.Rejected"){
    adv_txt.text = "The username is in use. Try with another username";
    }if (infoObject.code == "NetConnection.Connect.Failed"){
    adv_txt.text = "Connection to server failed. Try again ...";
    }if (infoObject.code == "NetConnection.Connect.Success") {
    users_so = SharedObject.getRemote("users_so", client_nc.uri, true);
    // connetto lo SharedObject al Flash Communication Server
    users_so.connect(client_nc);
    if (users_so.connect(client_nc)) {
      adv_txt.text="Connection object and URIs are OK. Wait for first onSync.";
    users_so.onSync = function() {
    // controlla nel debugger i valori assunti dalle proprietà
    //test = userList
    for ( var i in users_so.data ) {
    //_root.peopleonline.removeAll();
    if ( users_so.data[i] != null ) {
    traccia += users_so.data[i];
    //_root.peopleonline.addItem(users_so.data[i]);
    //usersonline=usersonline+users_so.data[i];
    //chat_txt.text=chat_txt.text+users_so.data[i];
    }
    }
    chat_txt.text=traccia;
    }
    }else {
      adv_txt.text="Can't connect - check URIs and the NetConnection object.";
    }
    }
    }
    }
    connectbutton.addEventListener("click", clicked);