Avatar of qfwp
qfwp
 asked on

Remote Shared Object not persisting.

Hi

I am currently attempting to make a class that reads a remote shared object and can also set properties.

I seem to be able to create a shared object, set a property and then read back that property, but only within the same session. The data does not seem to persist.

If I load up the browser after closing it the property i set is now undefined.

I have also noticed that i dont get any events from the NetStatus handler for the SharedObject, or any SyncEvent.
private var ncSharedObject:NetConnection
        private var globSO:SharedObject;
        private var globStrUserName:String;
        private var globFMSAPP:String;
            
        public function videoSO(strUserName:String, fmsApp:String){
        
            globStrUserName = strUserName;
            
            globFMSAPP = fmsApp;
        
            ncSharedObject = new NetConnection();
            ncSharedObject.addEventListener(NetStatusEvent.NET_STATUS, funcNetStatusHandler);
            ncSharedObject.addEventListener(SecurityErrorEvent.SECURITY_ERROR, funcSecurityErrorHandler);
            ncSharedObject.addEventListener(AsyncErrorEvent.ASYNC_ERROR,asyncErrorHandler);
            
            ncSharedObject.connect(fmsApp);
            
                
        }

        private function funcNetStatusHandler(evt:NetStatusEvent):void {
        
            funcDebug("status:" + evt.info.code);
        
            if (evt.info.code == "NetConnection.Connect.Success") {
            
                globBoolConnectionSuccessful = true;
            
                funcReadSharedObject();
            
            }
        
        }
        
        private function funcReadSharedObject():void {
        
            funcDebug("Getting Shared Object " + ncSharedObject.uri);
                    
            globSO = SharedObject.getRemote(globStrUserName, ncSharedObject.uri, true, false);
            
            funcDebug("??" + globSO.data);
            
            globSO.client = this;
            
            globSO.addEventListener(SyncEvent.SYNC, syncHandler);
            globSO.connect(ncSharedObject);
            
            
            globSO.addEventListener(NetStatusEvent.NET_STATUS, funcSOStatusHandler);
            
        
        }

        private function funcSOStatusHandler(evt:NetStatusEvent):void {
        
            funcDebug("SOstatus:" + evt.info.code);
        
        }
        
        private function syncHandler(evt:SyncEvent):void {
        
            funcDebug("syncHandler: " + globSO.data.userdata);
        
        }

        public function funcSetSharedObjectData(strUserName:String, numCDID:Number, numPosition:Number):void {
    
            funcDebug("size: " + globSO.size);
    
            funcDebug("SET SO - " + globSO.data.userdata);
    
            var objUser:objUserData;
            
            if (globSO.data.userdata == undefined){
                
                objUser = new objUserData();
                
                objUser.UserName = strUserName;
            
                globSO.setProperty("userdata", objUser);
                
                
            
            } else {
            
                objUser = globSO.data.userdata;
                
                objUser.UserName = new Date().toTimeString();
                
                globSO.setProperty("userdata", objUser);
                
            
            }
}
        public function funcGetLastPosition(strUserName:String, numCDID:Number):String {
        
            funcDebug("READ SO - " + globSO.data.userdata);
        
            var objUser:objUserData = globSO.data.userdata;
            
            return objUser.UserName;
}

Open in new window

Adobe FlashApache Flex

Avatar of undefined
Last Comment
Gary Benade

8/22/2022 - Mon
Gary Benade

I'm not 100% sure if this applies to FMS remote, but for local objects you need to cal flush to make sure the object is saved
        public function funcSetSharedObjectData(strUserName:String, numCDID:Number, numPosition:Number):void {
    
            funcDebug("size: " + globSO.size);
    
            funcDebug("SET SO - " + globSO.data.userdata);
    
            var objUser:objUserData;
            
            if (globSO.data.userdata == undefined){
                
                objUser = new objUserData();
                
                objUser.UserName = strUserName;
            
                globSO.setProperty("userdata", objUser);
                
                
            
            } else {
            
                objUser = globSO.data.userdata;
                
                objUser.UserName = new Date().toTimeString();
                
                globSO.setProperty("userdata", objUser);
                
            
            }
             // add this
             globSO.flush();
}

Open in new window

ASKER CERTIFIED SOLUTION
qfwp

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Gary Benade

apparently, you have to do this instead for remote objects:
globSO.setDirty();

http://polygeek.com/1251_flex_getting-dirty-with-remote-sharedobjects
Gary Benade

didn't see your post. OK. no problem.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy