0 Replies Latest reply on Mar 25, 2010 1:35 PM by Thombrar

    Problem using remote shared objects


      First of all, sorry for my bad english.. but I do my best. I'm making a kind of chat program, but I've the problem keeping an userlist with a remote shared object.

      The purpose is that each time a user joins, the application will add the user to this remote shared object.

      Now is the problem that this remote shared object is always undefined.. And I don't know why.. Can someone help me?



      Here is my code:


      The first thing I do is checking the user. When the user is able to join, the connection will be made. I added an eventlistener on the connection which will trigger a function "onConnectionNetStatus"

      when the connection succeeds. No problems so far..


      public function checkUser(userNaam:String):void{

           if(userExist(userNaam) == true){

                for each(var u:User in _alleUsers){

                     if(u.idUser == _gebruikerId && u.statusUser == "on"){

                          if(String(u.isAdmin) == "true" && uint(u.idUser) == 0){






                          _connectie = new NetConnection();


                          _connectie.addEventListener(NetStatusEvent.NET_STATUS, onConnectionNetStatus);

                          _connectie.client = this;



                trace("userLijst ", _user);


                throw new Error("Sorry, you can't join this meeting");





      In this function "onConnectionNetStatus" the remote shared object is made which I connect with the netconnection _connectie. The function loadUsers is also called. This function will check if there

      are already users in that RSO. If so, he will loop this RSO. Each user will be pushed in the array _user.The problem is that he never do this, because he can't get into this loop. The RSO is always undefined???



      private function onConnectionNetStatus(event:NetStatusEvent):void{

           trace("connection success")

           if(event.info.code == "NetConnection.Connect.Success"){


                for ( var prop:String in event.info)


                     trace("prop : "+prop+" = "+event.info[prop]+"\n");



                remoteSO = SharedObject.getRemote("RemoteSOUsers", _connectie.uri, false);


                remoteSO.addEventListener(SyncEvent.SYNC, SharObjFunc);

                remoteSO.client = this;




                throw new Error('Connection failed');





      private function loadUsers():void{

          if(remoteSO.data['userList'] != undefined){                                            

                if(Array(remoteSO.data['userList']).length > 0){

                     var tmp:Array = remoteSO.data['userList'] as Array;

                     for(var i:int = 0; i<tmp.length;i++){


                          var existingUser:User = new User();

                          existingUser.geslachtUser = tmp[i].geslachtUser;

                          existingUser.idUser = tmp[i].idUser;

                          existingUser.isAdmin = tmp[i].isAdmin;

                          existingUser.naamUser = tmp[i].naamUser;

                          existingUser.statusUser = tmp[i].statusUser;


                          if(String(existingUser.isAdmin) == "true" && uint(existingUser.idUser) == 0){














      As you see there is also a function addToRemote called. This function will push the new array with all users back into the remote shared object.


      //add user to remote

      private function addToRemote():void{

           remoteSO.setProperty("userList", _user);



      On that moment the function "SharObjFunc" will be triggered because the RSO changed (this because of the addeventlistener on the rso "remoteSO")  . An event will be triggered.. And the data will be updated.


      private function SharObjFunc(event:SyncEvent):void{

      var e:Event = new Event("DataLoadedUsers");




      Any help would be welcome. Thx!