flash on 2010-2-10

by junTMUG
♥0 | Line 29 | Modified 2010-02-10 19:27:57 | MIT License
play

ActionScript3 source code

/**
 * Copyright junTMUG ( http://wonderfl.net/user/junTMUG )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/2mlz
 */

package {
	import flash.text.TextField;
	import flash.accessibility.Accessibility;
    import flash.display.Sprite;
    import flash.net.NetConnection;
    import flash.net.SharedObject;
    public class ChatServer extends Sprite {
        var my_nc:NetConnection;
        var Comments:TextField;
        var myComment:TextField;
        
        public function ChatServer() {
            // write as3 code here..
            my_nc = new NetConnection();
			my_nc.connect("rtmp://localhost/bbs");
			bbs();
			//SharedObjectをサーバーに接続
        }
		
		function bbs(){
			//sharedObjectを作る
			//getRemoteメソッドの第一引数はSharedObjectの名前、第二引数はURL。URLはNetConnection.uriプロパティで取得できる。
			var so = SharedObject.getRemote("shared_text",my_nc.uri);
			//SharedObjectが変更されたときの処理
			//SharedObjectが変更されるとonSyncイベントが呼び出されるのでイベントハンドラメソッドを作る
			so.onSync=function(){
				trace("SharedObjectが変更されました");
				Comments.text = so.data.comments;//このスコープの中ではthissoを指す
			}
			so.connect(my_nc);
			so.onRelease=function(){
				so.data.comments += "\n" + myComment.text;
				myComment.text = "";
			}
        }
    }
}