flash中http应用

flash通过http获取数据,params向http传入参数。
_loader = new URLLoader();
			var request:URLRequest = new URLRequest(ConstData.APP_ADDR);//请求地址
			var params:URLVariables = new URLVariables();				//参数
			params.action = _obj.type;										//参数-请求类型
			params.userName = encodeURI(ConstData.userSelf.name);			
			params.addName = encodeURI(_obj.name);						
			request.method = URLRequestMethod.POST;
			request.data = params;
			_loader.addEventListener(Event.COMPLETE, dataHandler);
			_loader.addEventListener(ProgressEvent.PROGRESS, progressHandler);
			_loader.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
			_loader.load(request);

private function dataHandler(e:Event):void {
			var result:String = String(URLLoader(e.target).data);
			if(result) {
				switch(result) {
					//做相应的处理
				}
			}
		}
		
		private function progressHandler(e:ProgressEvent):void {
			//trace(e.bytesLoaded);
		}
		
		private function errorHandler(e:IOErrorEvent):void {
			
			_loader.close();
			_loader = null;
		}

你可能感兴趣的:(Flash)