191 lines
6.0 KiB
ActionScript
191 lines
6.0 KiB
ActionScript
package com.control.connect
|
|
{
|
|
import com.InstallFace;
|
|
import com.comfig.PathConfig;
|
|
import com.control.ConnectService;
|
|
import com.control.data.ReturnBean;
|
|
import com.events.DevEvent;
|
|
import com.utils.Utils;
|
|
import com.view.ui.message.MessageBoxUI;
|
|
import flash.events.AsyncErrorEvent;
|
|
import flash.events.Event;
|
|
import flash.events.IOErrorEvent;
|
|
import flash.events.NetStatusEvent;
|
|
import flash.events.SecurityErrorEvent;
|
|
import flash.net.*;
|
|
import flash.utils.setTimeout;
|
|
|
|
public class Connect
|
|
{
|
|
|
|
registerClassAlias("ReturnBean",ReturnBean);
|
|
|
|
private var str:String;
|
|
|
|
private var nc:NetConnection;
|
|
|
|
public var actUrl:String;
|
|
|
|
private var lastMethod:String;
|
|
|
|
public function Connect()
|
|
{
|
|
super();
|
|
this.nc = new NetConnection();
|
|
this.nc.client = this.nc;
|
|
this.nc.objectEncoding = ObjectEncoding.AMF0;
|
|
this.nc.addEventListener(NetStatusEvent.NET_STATUS,this.onConStatus);
|
|
this.nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR,this.onAsyncError);
|
|
this.nc.addEventListener(IOErrorEvent.IO_ERROR,this.onIoerror);
|
|
this.nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onSecurityError);
|
|
this.str = PathConfig.getInstance().getWebPath() + "gateway";
|
|
this.nc.connect(this.str);
|
|
}
|
|
|
|
public function connect(param1:String, param2:Function, ... rest) : void
|
|
{
|
|
if(InstallFace.getInstance().isValid)
|
|
{
|
|
return;
|
|
}
|
|
if(!InstallFace.getInstance().isConnect)
|
|
{
|
|
MessageBoxUI.getInstance().reLogin("你已断开连接,请重新登录游戏");
|
|
return;
|
|
}
|
|
if(param1 == this.lastMethod)
|
|
{
|
|
switch(rest.length)
|
|
{
|
|
case 0:
|
|
setTimeout(this.connect1,200,param1,param2);
|
|
break;
|
|
case 1:
|
|
setTimeout(this.connect2,200,param1,param2,rest[0]);
|
|
break;
|
|
case 2:
|
|
setTimeout(this.connect3,200,param1,param2,rest[0],rest[1]);
|
|
break;
|
|
case 3:
|
|
setTimeout(this.connect4,200,param1,param2,rest[0],rest[1],rest[2]);
|
|
break;
|
|
case 4:
|
|
setTimeout(this.connect5,200,param1,param2,rest[0],rest[1],rest[2],rest[3]);
|
|
}
|
|
return;
|
|
}
|
|
this.lastMethod = param1;
|
|
switch(rest.length)
|
|
{
|
|
case 0:
|
|
this.nc.call(param1,new Responder(param2,this.ErrStatus));
|
|
break;
|
|
case 1:
|
|
this.nc.call(param1,new Responder(param2,this.ErrStatus),rest[0]);
|
|
break;
|
|
case 2:
|
|
this.nc.call(param1,new Responder(param2,this.ErrStatus),rest[0],rest[1]);
|
|
break;
|
|
case 3:
|
|
this.nc.call(param1,new Responder(param2,this.ErrStatus),rest[0],rest[1],rest[2]);
|
|
break;
|
|
case 4:
|
|
this.nc.call(param1,new Responder(param2,this.ErrStatus),rest[0],rest[1],rest[2],rest[3]);
|
|
}
|
|
setTimeout(this.clearMethod,100);
|
|
}
|
|
|
|
private function clearMethod() : void
|
|
{
|
|
this.lastMethod = "";
|
|
}
|
|
|
|
private function connect1(param1:String, param2:Function) : void
|
|
{
|
|
this.connect(param1,param2);
|
|
}
|
|
|
|
private function connect2(param1:String, param2:Function, param3:*) : void
|
|
{
|
|
this.connect(param1,param2,param3);
|
|
}
|
|
|
|
private function connect3(param1:String, param2:Function, param3:*, param4:*) : void
|
|
{
|
|
this.connect(param1,param2,param3,param4);
|
|
}
|
|
|
|
private function connect4(param1:String, param2:Function, param3:*, param4:*, param5:*) : void
|
|
{
|
|
this.connect(param1,param2,param3,param4,param5);
|
|
}
|
|
|
|
private function connect5(param1:String, param2:Function, param3:*, param4:*, param5:*, param6:*) : void
|
|
{
|
|
this.connect(param1,param2,param3,param4,param5,param6);
|
|
}
|
|
|
|
public function checkResult(param1:ReturnBean) : Boolean
|
|
{
|
|
if(param1.result == ReturnBean.STATUS_2)
|
|
{
|
|
MessageBoxUI.getInstance().reLogin();
|
|
return true;
|
|
}
|
|
if(param1.result == ReturnBean.STATUS_1)
|
|
{
|
|
if(param1.msg == null)
|
|
{
|
|
param1.msg = "系统错误";
|
|
}
|
|
MessageBoxUI.getInstance().addMessage(param1.msg);
|
|
return true;
|
|
}
|
|
if(param1.result == ReturnBean.STATUS_3)
|
|
{
|
|
if(param1.msg == null)
|
|
{
|
|
param1.msg = "系统错误";
|
|
}
|
|
MessageBoxUI.getInstance().addMessage(param1.msg);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function ErrStatus(param1:Object) : void
|
|
{
|
|
MessageBoxUI.getInstance().addMessage("服务器连接出错");
|
|
}
|
|
|
|
private function onConStatus(param1:NetStatusEvent) : void
|
|
{
|
|
if(param1.info.code == "NetConnection.Connect.Success")
|
|
{
|
|
}
|
|
if(param1.info.code == "NetConnection.Call.Failed")
|
|
{
|
|
MessageBoxUI.getInstance().addMessage("服务器连接失败");
|
|
Utils.g_events.dispatchEvent(new DevEvent(DevEvent.UNCONNSERVER));
|
|
}
|
|
}
|
|
|
|
private function onIoerror(param1:IOErrorEvent) : void
|
|
{
|
|
}
|
|
|
|
private function onSecurityError(param1:SecurityErrorEvent) : void
|
|
{
|
|
}
|
|
|
|
private function onAsyncError(param1:AsyncErrorEvent) : void
|
|
{
|
|
}
|
|
|
|
public function dispatchEvent(param1:Event) : void
|
|
{
|
|
ConnectService.getInstance().dispatchEvent(param1);
|
|
}
|
|
}
|
|
}
|
|
|