⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dataservice.as

📁 flex 实现的一个showcase 喜欢flex的朋友可以
💻 AS
字号:
package com.teknision.net.remote.service{
	
	import flash.events.*;
	import flash.net.URLRequest;
	import flash.net.URLVariables;
	
	public class DataService{
		
///////////////////////////////////////////////////////////////////////////////
		
		public var service_config:DataServiceConfig;
		public var result:Object;
		
///////////////////////////////////////////////////////////////////////////////
		
		private var __loader:URLLoader;
		
		
///////////////////////////////////////////////////////////////////////////////
		
		
		public function DataService(i_service_config:DataServiceConfig){
			super();
			service_config=i_service_config;
		}

///////////////////////////////////////////////////////////////////////////////	

		
		public function invoke(service_vars:URLVariables):void{
		
			if(!canInvoke()){
				var config_er:Error= new Error("DataServiceConfig is not loaded, cannot proceed to load remote data");
				throw(config_er);
			}else{
				var req:URLRequest=buildRequest(service_vars);
				load(req);
			}
			
		}
		
		
		public function canInvoke():Boolean{
			var r_val:Boolean=true;
			if(service_config.requiresload && !service_config.loaded){
				r_val=false;
			}
			return r_val;
		}
		
///////////////////////////////////////////////////////////////////////////////	

		public function load(i_req:URLRequest):void{
			__loader=new URLLoader();
			configureLoader(__loader);
			
			__loader.addEventListener(Event.COMPLETE,handleDataLoad);
			__loader.addEventListener(IOErrorEvent.IO_ERROR,handleDataFailed);
			__loader.load(i_req);
		}
		
		
		
		public function buildRequest(service_vars:URLVariables):URLRequest{
			//OVERRIDE
			var req:URLRequest=new URLRequest("");
			req.data=service_vars;
			return req;
		}
		
		
		public function configureLoader(i_loader:URLLoader):void{
			//OVERRIDE
		}
		
		
		public function populateFromData(i_data:String):void{
			//OVERRIDE
			result=i_data;
		}
		
///////////////////////////////////////////////////////////////////////////////	
			
		private function handleDataLoad(event:Event):void{
			event.stopPropagation();
			populateFromData(__loader.data);
			var o_event:Event=new Event(Event.COMPLETE);
			dispatchEvent(o_event);
		}
		
		
		
		private function handleDataFailed(event:IOErrorEvent):void{
			event.stopPropagation();	
			var o_event:IOErrorEvent=new IOErrorEvent(IOErrorEvent.IO_ERROR);
			dispatchEvent(o_event);
		}



///////////////////////////////////////////////////////////////////////////////	

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -