sharedObject1

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initCollection()">
	<mx:Script>
		<![CDATA[
			import flash.net.*;
			var net:NetConnection;
			[Bindable]
			var soChat:SharedObject;
			private function initCollection():void{
			NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF3;
			SharedObject.defaultObjectEncoding  = flash.net.ObjectEncoding.AMF3;	
			net=new NetConnection();
			net.addEventListener(NetStatusEvent.NET_STATUS,showError);
			net.connect("rtmp://127.0.0.1/red");//我用的是red5,/ red是我的一个随便的应用
			addEvent();

		}
		public function addEvent():void{
				
				soChat = SharedObject.getRemote( "ssss", net.uri, true );
//				soChat=SharedObject.getLocal("move");//可以保存本地信息,重启两次,soChat.data.username还在 
				soChat.addEventListener(SyncEvent.SYNC,syncAction);
				soChat.client = this;
				soChat.connect(net);
				
				soChat.data.username="hello";
				
				
		}
		public function showError(e:NetStatusEvent):void{
				trace(e.info.code);
				trace(e.info.code=="NetConnection.Connect.Success");
				if(e.info.code!="NetConnection.Connect.Success"){
					mx.controls.Alert.show("服务器连接失败");
				}
		}
		public function syncAction(e:SyncEvent){
			trace("sync");
//			if(e.changeList[0].code=="change"){
//				trace("change");
//			}
		}
		public function test(){
			soChat.data.username=text.text;
			trace(soChat.data.username)
			str.text=soChat.data.username;//输出 text.text中的内容
			soChat.setProperty("username","yyyyy");
			soChat.send("hello",text.text);
		}
		public function hello(txt:String){
			str.text=soChat.data.username;//输出yyyy
		}
		]]>
	</mx:Script>
	<mx:Button x="35" y="313" label="Button" click="test()"/><!--点一下是yyyy,再点下是ssss不知道为什么-->
	<mx:TextInput x="25" y="36" id="text" text="ssss"/>
	<mx:TextInput x="205" y="36" text="" id="str">
		
	</mx:TextInput>
 </mx:Application>

 

你可能感兴趣的:(.net,xml,应用服务器,Flash,Adobe)