AS 3オンラインWEBチャット


package cn.cjxo
{import flash.display.Sprite;
	import flash.events.DataEvent;
	import flash.events.Event;
	import flash.external.ExternalInterface;
	import flash.net.XMLSocket;
	/**
	 * @author ChenJianxiang
	 * @deprecated JavaSocket->ActionSocket<-JavaSocketServer
	 * function SocketConnect(host,port){}		//JavaScript CALL ActionScript   
	 * function SocketSend(data){}				//JavaScript CALL ActionScript   
	 * function SocketClose(){}					//JavaScript CALL ActionScript   
	 * function SocketOnInit(){}				//   
	 * function SocketOnConnect(success){}		//ActionScript CALL JavaScript     
	 * function SocketOnData(data){}			//ActionScript CALL JavaScript        
	 * function SocketOnClose(){} 				//ActionScript CALL JavaScript       
	 *   flash xmlSocket client    xml,   ”\0
” */ public class Main extends Sprite { private var xmlSocket:XMLSocket = null; public function Main():void { if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); //ExternalInterface.call("cal", " 9!!"); ExternalInterface.addCallback("SocketConnect", _socketConnect); ExternalInterface.addCallback("SocketSend", _socketSend); ExternalInterface.addCallback("SocketClose", _socketClose); //ExternalInterface.addCallback("SocketOnInit", _socketConnect); xmlSocket.addEventListener(Event.CONNECT, function(e:Event):void{ //ActionScript CALL JavaScript ExternalInterface.call("SocketOnConnect", xmlSocket.connected); }); xmlSocket.addEventListener(DataEvent.DATA, function(e:Event):void { //ActionScript CALL JavaScript ExternalInterface.call("SocketOnData", ""); }); xmlSocket.addEventListener(Event.CLOSE, function(e:Event):void { //ActionScript CALL JavaScript ExternalInterface.call("SocketOnClose", ""); }); } private function init(e:Event = null):void{ removeEventListener(Event.ADDED_TO_STAGE, init); if(xmlSocket == null){ xmlSocket = new XMLSocket();// XMLSocket } } /** * * @param host * @param port */ private function _socketConnect(host:String, port:int):void { if (xmlSocket.connected) { ExternalInterface.call("cal", " "); // return; } xmlSocket.connect(host, port); } /** * * @param message */ private function _socketSend(message:String):void { xmlSocket.send(message); } private function _socketClose():void { xmlSocket.close(); } } }