Skip to main content
jacograaff
Known Participant
February 28, 2012
Question

shared object with complex values

  • February 28, 2012
  • 1 reply
  • 1186 views

My remote shared object on the server was created like this...

var userList = new Array();

application.onAppStart = function(){

this.usersSO = SharedObject.get("userList", false);

}

then on connect I create a new object and put that into the so-list

application.onConnect = function(client, user){

application.acceptConnection(client);

     var newUser = new Object();

    newUser.userName = user.userName;

    newUser.userID = user.userID;

    newUser.userStatus = user.userStatus;

this.usersSO.setProperty(user.userID, newUser);

}

I can clear the user:

this.usersSO.setProperty(client.userID, null);

but how do I set a value like

userStatus

when it is inside a object refered to by the so name-id

setProperty(userID, simpleValue);

if I added simple values like

this.usersSO.setProperty('simpleName', "nameABC");

then I could

setProperty('simpleName', "nameNEW");

- is the only way to call a script on the server and set the original userList reference of the user adn then send a call with update function to all connected clients???

thanks

    This topic has been closed for replies.

    1 reply

    jacograaff
    Known Participant
    February 28, 2012

    the way I am doing it now:

    in main.asc

    -----------------------------------

    Client.prototype.changeConsultantStatus = function(action, selectedUserID, client){

       

         trace("server.changeStatus: "+action+", to: "+selectedUserID+", from: "+client.userName);

      

          users[selectedUserID].userStatus = action;

        application.broadcastMsg("updateRemoteStatus",selectedUserID, action);   

       

    }

    -----------------------------------

    then in my flex/AIR app

    -----------------------------------

    private function updateRemoteStatus(event):void{

        var _selectedUserID:String = event.infoObject.selectedUserID;

        var _action:String = event.infoObject.action;

        for (var n:int = 0; n < consultantCollection.length; n++){

            if((consultantCollection.userID) == _selectedUserID){

                traceStr("Set status for: " + consultantCollection.userName+" to "+_action);

                consultantCollection.userStatus = _action;

                consultantCollection.refresh();

                //found it - don't look further

                break;

            }

        }

    -----------------------------------

    Ideally the default update on a sharedobject change should run - like when i add or delete a "user" from the sharedobject

    but i really need to change a value of a property of an existing user inside the sharedobject

       

    }

    -----------------------------------

    jacograaff
    Known Participant
    February 28, 2012

    ok - i am looking at this explanation (goes beyond the basic adobe ball.x and ball.y example)

    http://www.justskins.com/forums/remote-shared-object-78616.html

    will implement it...

    jacograaff
    Known Participant
    February 28, 2012

    i tried:

    ------------------------------------------------------------------------

    Client.prototype.changeConsultantStatus = function(action, selectedUserID, client){

       

        trace("server.changeStatus: "+action+", to: "+selectedUserID+", from: "+client.userName);

       

        users[selectedUserID].userStatus = action;

       

        /* option 1 */

        //tempUser = this.usersSO.get[selectedUserID]; // -------------------------  throws error - TypeError: this.usersSO has no properties

        tempUser = users[selectedUserID];

       

        tempUser.userStatus = action;

        this.usersSO.setProperty(selectedUserID, tempUser); // will also throw error when reffering to usersSO inside Client.prototype.function

       

        /* option 2 */

        //client.userStatus = action;

        //application.broadcastMsg("updateRemoteStatus",selectedUserID, action);   

       

    }

    ------------------------------------------------------------------------------------------

    when refering to shared object inside a Client.prototype.function

    I get

    TypeError: this.usersSO has no properties

    -- the second option works though