Return to Snippet

Revision: 17928
at September 17, 2009 02:23 by mprabhuram


Initial Code
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
	 creationComplete="onAppStart()">
<mx:Script>
	<![CDATA[
	
		// Declaring variables
		public var nc:NetConnection;
		private var videoURL:String = "rtmp://localhost/sampleapp/_definst_";
		public var remoteSO:SharedObject; 
	
		public function onAppStart():void
		{
			// 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,false);
    		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 
        {        	
        	remoteText.text = remoteSO.data.propertyName;	
        } 
        
        // update the contents of the remote shared object from this client     
        private function changeRemoteSO():void
        {        	     	
        	remoteSO.setProperty("propertyName",localText.text);
        	
        }
        
        
        
	]]>
</mx:Script>	
	<mx:Button x="427" y="217" label="Change Remote Text" click="changeRemoteSO()"/>
	<mx:Text x="319" y="142" text="Remote Text :" width="88" height="24"/>
	<mx:Text x="331.5" y="43" text="Remote Shared Object Demo" width="318" height="30" fontFamily="Georgia" fontSize="23"/>
	<mx:Text x="319" y="174" text="Local Text :" width="88" height="24"/>
	<mx:TextInput x="427" y="140" id="remoteText"/>
	<mx:TextInput x="427" y="172" id="localText"/>
	
</mx:Application>

Initial URL

                                

Initial Description
This is a sample application to demonstrate how to create and modify remote shared objects in a flex client application

Initial Title
Creating and modifying remote shared objects from flex client

Initial Tags
actionscript, Flex

Initial Language
ActionScript 3