Creating and modifying remote shared objects from flex client


/ Published in: ActionScript 3
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
  3. creationComplete="onAppStart()">
  4. <mx:Script>
  5. <![CDATA[
  6.  
  7. // Declaring variables
  8. public var nc:NetConnection;
  9. private var videoURL:String = "rtmp://localhost/sampleapp/_definst_";
  10. public var remoteSO:SharedObject;
  11.  
  12. public function onAppStart():void
  13. {
  14. // Establishing connection to the server application
  15. nc = new NetConnection();
  16. trace("Application Launched " );
  17.  
  18. //Event listener to capture the net connection status
  19. nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
  20. nc.connect(videoURL);
  21.  
  22. }
  23.  
  24. private function netStatusHandler(event:NetStatusEvent):void
  25. {
  26. switch (event.info.code)
  27. {
  28. //Successful connection to the server
  29. case "NetConnection.Connect.Success":
  30. trace("Connected to server: " + videoURL);
  31. createARemoteSO();
  32. break;
  33. }
  34. }
  35.  
  36. private function createARemoteSO():void
  37. {
  38. // Create or get reference to the remote shared object
  39. remoteSO = SharedObject.getRemote("remoteSO",nc.uri,false);
  40. remoteSO.connect(nc);
  41.  
  42. // Event listener to handlr changes to the remote shared object
  43. remoteSO.addEventListener(SyncEvent.SYNC, remoteSOChanged);
  44. }
  45.  
  46. // This function is called when ever a change is made to the remote shared object by other clients/ server app
  47. private function remoteSOChanged(se:SyncEvent):void
  48. {
  49. remoteText.text = remoteSO.data.propertyName;
  50. }
  51.  
  52. // update the contents of the remote shared object from this client
  53. private function changeRemoteSO():void
  54. {
  55. remoteSO.setProperty("propertyName",localText.text);
  56.  
  57. }
  58.  
  59.  
  60.  
  61. ]]>
  62. </mx:Script>
  63. <mx:Button x="427" y="217" label="Change Remote Text" click="changeRemoteSO()"/>
  64. <mx:Text x="319" y="142" text="Remote Text :" width="88" height="24"/>
  65. <mx:Text x="331.5" y="43" text="Remote Shared Object Demo" width="318" height="30" fontFamily="Georgia" fontSize="23"/>
  66. <mx:Text x="319" y="174" text="Local Text :" width="88" height="24"/>
  67. <mx:TextInput x="427" y="140" id="remoteText"/>
  68. <mx:TextInput x="427" y="172" id="localText"/>
  69.  
  70. </mx:Application>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.