Welcome, Guest
  • Author Topic: New Shared Object (age) for private chat  (Read 1757 times)

    jepyssimo

    • Seasoned Programmer
    • ***
    • Posts: 118
      • View Profile
      • Email
    New Shared Object (age) for private chat
    « on: 11/25/06, 06:36 »
    Hi, I want add a new SharedObject for private chat.
    I store user's age in a variable:

    age = _root.age.text;

    I send this variable (age) to server:

       // Connect to the application
       client_nc.connect("rtmp:/flashdb", username.text, age);
       //Store username and move to Main screeen
       client_nc.setUser = function(name) {
          _global.username = name;
          gotoAndStop("Main");
       };
    Now, how I store a variable in SharedObject?
    Thanks

    kofi addaquay

    • Global Moderator
    • Senior Programmer
    • *****
    • Posts: 450
      • View Profile
      • Scripton Interactive
      • Email
    Re: New Shared Object (age) for private chat
    « Reply #1 on: 11/27/06, 22:25 »
    a local or remote shared object? i am assuming a local shared object

    var local_so:SharedObject = SharedObject.getLocal("ConfigData");

    so if you are talking about age variable

    then
    local_so.data.age = age;

    what about retrieving. well,
    first check to see if the data exists

    if(local_so.data.age != undefined)
    {
       //data exist
       trace(local_so.data.age);  <-- this will show u ur value. you can even assign a variable to it etc.
    else
    {
       //no data - prompt user
    }
    }


    hope this helps and hope i understood ur question right
    « Last Edit: 11/27/06, 22:32 by kofi addaquay »

    jepyssimo

    • Seasoned Programmer
    • ***
    • Posts: 118
      • View Profile
      • Email
    Re: New Shared Object (age) for private chat
    « Reply #2 on: 12/16/06, 07:47 »
    Sorry,  It is a remote shared object ...

    kofi addaquay

    • Global Moderator
    • Senior Programmer
    • *****
    • Posts: 450
      • View Profile
      • Scripton Interactive
      • Email
    Re: New Shared Object (age) for private chat
    « Reply #3 on: 12/17/06, 13:05 »
    Hmm.. Remote shared objects are created using SharedObject.getRemote() but do not dynamically share information until they are connected to the server using a netconnection object and have been synchronized with a copy of the shared object on the server.

    thus / something like this

    var nc:NetConnection = new NetConnection();
    nc.connect("rtmp:/myFlashApp");
    remote_so = SharedObject.getRemote("UsersData", nc.uri);

    to make sure you RSO is working across the network you would have execute a statment like

    if(remote_so.connect(nc))
    {
        //then set or get ur data here
    }
    else
    {
        //the connection failed
    }

    setting the variables is almost the same as in local shared objects
    u could do something like
    age.text = remote_so.data.age

    or if you were using arrays or objects
    age.text = remote_so.data[TheUser].age

    thats the basic idea. hope this helps or at least puts you on the right path.

    Kofi Addaquay