5 Replies Latest reply: Feb 28, 2012 4:56 AM by JayCharles RSS

    shared object with complex values

    jacograaff Community Member

      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

        • 1. Re: shared object with complex values
          jacograaff Community Member

          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[n].userID) == _selectedUserID){

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

                      consultantCollection[n].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

           

           

           

             

          }

           

           

           

           

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

          • 2. Re: shared object with complex values
            jacograaff Community Member

            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...

            • 3. Re: shared object with complex values
              jacograaff Community Member

              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

              • 4. Re: shared object with complex values
                jacograaff Community Member

                it seems like serverside I will have to declare/instantiate the sharedobject again and link it with the stored userList variable

                 

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

                 

                as seen at

                http://echo.ryerson.ca/fcsEchoSite/arraysSharedObjects/index.html

                  I don t have to on

                 

                application.onDisconnect and other application level functions

                 

                but I have to on

                 

                Client.prototype.someFunction and client level related functions

                 

                I'll try a bit later .....

                • 5. Re: shared object with complex values
                  JayCharles Community Member

                  I *think* I understand what you're asking here...

                   

                  If you need to update a property within an object that is the value of a sharedobject slot, you need to get the property, change the value, and then set the property again.

                   

                  var obj = my_so.getProperty("someslot");

                  obj.someproperty = somevalue

                  my_so.setProperty("someslot", obj);