当前位置: 首页 > 工具软件 > Zend AMF > 使用案例 >

ZendAMF通信类 AS3与PHP通信

唐茂实
2023-12-01
package helper
{
	import config.ConfigVar;
	import config.ConfigZendAMF;
	
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.net.NetConnection;
	import flash.net.Responder;

	public class HH_ZendAMF
	{
		public function HH_ZendAMF()
		{
		}
		
		//通信类:ZendAMF通信类
		public static function zendAMF(postStr:String,arr:Array,trueFun:Function=null,zeroFun:Function=null,errorFun:Function=null,isLoading:Boolean=false,lodingIsBg:Boolean=false,sitePoint:Point=null,sizePoint:Point=null,url:String=null):Function
		{
			if(sitePoint==null)
			{
				sitePoint = new Point(336,205);
			}
			if(sizePoint==null)
			{
				sizePoint = new Point(278,157);
			}
			
			var fun:Function;
			if(isLoading==true)
			{
				var lodingSp:Sprite = new Sprite();
				ConfigVar.KEEPSP.addChild(lodingSp);
				var loding:HH_Loading = new HH_Loading(lodingSp,null,"one","HTTP");
				loding.showLoading("",lodingIsBg,sitePoint.x,sitePoint.y,sizePoint.x,sizePoint.y);
			}
			var backFun:Function = function(obj:Object):void
			{
				if(isLoading==true)
				{
					ConfigVar.KEEPSP.removeChild(lodingSp);
				}
				
				//返回给过为0时的处理
				if(obj=="0")
				{
					if(zeroFun!=null)
					{
						zeroFun();
					}else{
						_zeroFun(postStr);
					}
				}
				//返回结果出错时的处理
				else if(obj=="-1")
				{
					if(errorFun!=null)
					{
						errorFun();
					}else{

						_errorFun(postStr);
					}
				}
				//返回正确结果是的处理
				else
				{
					if(trueFun!=null)
					{
						trueFun(obj);
					}
				}
			}
			
			if(arr==null)
			{
				arr = new Array();
			}
			if(url==null || url==""){ url = ConfigZendAMF.amfURL; }
			var rsp:Responder = new Responder(backFun);
			var conn:NetConnection = new NetConnection();
			conn.connect(url);
			conn.call(postStr, rsp, arr);
			fun = function():void
			{
				conn.close();
				if(isLoading==true)
				{
					ConfigVar.KEEPSP.addChild(lodingSp);
					ConfigVar.KEEPSP.removeChild(lodingSp);
				}
			};
			
			return fun;
		}
		
		/**
		 * 返回结果为零时的处理
		 * */
		private static function _zeroFun(postStr:String):void
		{
			
		}
		
		/**
		 * 返回结果出错时的处理
		 * */
		private static function _errorFun(postStr:String):void
		{
			
		}
	}
}

用法如下: HH_ZendAMF.zendAMF("webgame_controller.get_users",null,getUserRole,zeroFun,errorFun,true,true);

 类似资料: