Link to home
Start Free TrialLog in
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

Avatar of Gary Benade
Gary Benade
Flag of South Africa image

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
Avatar of qfwp
qfwp

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
apparently, you have to do this instead for remote objects:
globSO.setDirty();

http://polygeek.com/1251_flex_getting-dirty-with-remote-sharedobjects
didn't see your post. OK. no problem.