3 Replies Latest reply on May 20, 2010 9:27 PM by stratusboylost

    Stratus SharedObject.getRemote(); never gives a SyncEvent? Even on change we do not get a sync

    stratusboylost

      The following is the code i m using to try a simple sharedObject getRemote to share state among different Stratus clients, but the SyncEvent never gets fired, so how do we share state across Stratus clients? Thanks a lot

       

       

      package
      {
      import flash.display.Sprite;
      import flash.events.NetStatusEvent;
      import flash.net.NetConnection;
      import flash.net.NetGroup;
      import flash.net.*;
      import flash.events.*;
      import flash.net.SharedObject;
      import flash.text.*;

      import flash.media.Camera;
      import flash.media.Video;
      import flash.events.MouseEvent;
      import flash.display.LoaderInfo;
      import fl.controls.Button;

      /**
        * ...
        * @author mark
        */
      public class  RemoteSharedObject extends Sprite
      {
        // Singleton
        public static var _instance:RemoteSharedObject;
        // Singleton
        public static function get instance():RemoteSharedObject {
         if(_instance == null ) {
               _instance = new RemoteSharedObject();
            }

            return _instance;
        }
       
        const SERVER:String = 'rtmfp://stratus.adobe.com/';
        const DEVKEY:String = key';
       
         // Declaring variables
        public var nc:NetConnection;
        private var videoURL:String = SERVER+DEVKEY;
        public var remoteSO:SharedObject;
        var localText:TextField, remoteText:TextField;
        public function RemoteSharedObject():void
        {
        
        
         localText = new TextField();
         localText.x = 100; localText.y = 100;
         localText.type = TextFieldType.INPUT;
         localText.backgroundColor = 0xEBF9B7;
         localText.autoSize = TextFieldAutoSize.CENTER;
         localText.width = 100;
         localText.height = 30;
         localText.text = 'local';
         addChild(localText);
        
        
         addEventListener(MouseEvent.CLICK ,changeRemoteSO);
        
        
         remoteText = new TextField();
         remoteText.x = 100; remoteText.y = 200;
         remoteText.backgroundColor = 0xE4F7FA;
         remoteText.type = TextFieldType.DYNAMIC;
         remoteText.autoSize = TextFieldAutoSize.CENTER;
         remoteText.width = 100;
         remoteText.height = 30;
         remoteText.text = 'remote';
         addChild(remoteText);
         // Establishing connection to the server application
         nc = new NetConnection();
         trace("Application Launched " );
         //Event listener to capture the net connection status
         nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
         nc.connect(videoURL);
        
        
        }

        private function netStatusHandler(event:NetStatusEvent):void
        {
                  switch (event.info.code)
                  {
                   //Successful connection to the server
                      case "NetConnection.Connect.Success":
                          trace("Connected to server: " + videoURL);
                          createARemoteSO();
                          break;
                  }
              }

              private function createARemoteSO():void
              {
         // Create or get reference to the remote shared object
            remoteSO = SharedObject.getRemote("remoteSO",nc.uri,true);
            remoteSO.connect(nc);

            // Event listener to handlr changes to the remote shared object
            remoteSO.addEventListener(SyncEvent.SYNC, remoteSOChanged);
              }

              // This function is called when ever a change is made to the remote shared object by other clients/ server app
              private function remoteSOChanged(se:SyncEvent):void
              {
               trace('remote ',remoteSO.data.propertyName);
         remoteText.text = remoteSO.data.propertyName;
        
              }

              // update the contents of the remote shared object from this client
              private function changeRemoteSO(evt:Event):void
              {
               remoteSO.setProperty("propertyName",localText.text);
         trace('local ',localText.text);
              }
      }

      }