`

Module加载

    博客分类:
  • Flex
 
阅读更多

package net.lanelife.framework.catwindows.core
{
	import flash.events.ProgressEvent;
	import flash.system.ApplicationDomain;
	
	import mx.core.FlexGlobals;
	import mx.events.ModuleEvent;
	import mx.modules.IModuleInfo;
	import mx.modules.ModuleManager;
	
	import net.lanelife.framework.catwindows.utils.ProgressBar;

	[Bindable]
	public class Application
	{
		
		public var name:String;
		public var moduleUrl:String;
		
		
		private var module:IModuleInfo;
		
		private var progressBar:ProgressBar;
		
		
		public function run():void
		{
			module = ModuleManager.getModule(moduleUrl);   
			
			module.addEventListener(ModuleEvent.READY, module_readyHandler);   
			module.addEventListener(ModuleEvent.PROGRESS, module_progressHandler);
			module.addEventListener(ModuleEvent.ERROR, module_errorHandler);
			if (module.loaded)
			{
				start();
			}
			else
			{
				progressBar = new ProgressBar();
				module.load(ApplicationDomain.currentDomain);
			}
		}
		
		private function start():void
		{
			//trace("========"+module.url)
			var application:IApplication = module.factory.create() as IApplication;    
			FlexGlobals.topLevelApplication.addElement(application);
			application.run();
			module.unload();
		}
		
		private function module_readyHandler(event:ModuleEvent):void
		{
			event.target.removeEventListener(ModuleEvent.READY, module_readyHandler);
			event.target.removeEventListener(ModuleEvent.PROGRESS, module_progressHandler);
			event.target.removeEventListener(ModuleEvent.ERROR, module_errorHandler);
			
			progressBar.close();
			start();
		}
		
		private function module_progressHandler(event:ModuleEvent):void
		{
			//trace(module.url)
			progressBar.progress(event as ProgressEvent, "正在加载"+name+",请稍候...");
		}
		
		private function module_errorHandler(event:ModuleEvent):void
		{
			event.target.removeEventListener(ModuleEvent.READY, module_readyHandler);
			event.target.removeEventListener(ModuleEvent.PROGRESS, module_progressHandler);
			event.target.removeEventListener(ModuleEvent.ERROR, module_errorHandler);
			progressBar.showError(name+"加载失败:"+event.errorText);
		}
	}
}

 模块加载代码,用法:

loginApplication = new net.lanelife.framework.catwindows.core.Application();
				loginApplication.name = "登录程序";
				loginApplication.moduleUrl = "os/software/net/lanelife/webos/soft/login/Login.swf";
				
				loginApplication.run();
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics