首页 > 代码库 > Flex ModuleManager 加载模块

Flex ModuleManager 加载模块

import mx.events.ModuleEvent;import mx.modules.IModuleInfo;import mx.modules.ModuleManager;private var _moduleInfo:IModuleInfo;private function loadModule(url:String):void{                  var tempModuleInfo:IModuleInfo = ModuleManager.getModule(url);                   //注释或使用下面一行,运行查看不同的效果   _moduleInfo = tempModuleInfo;                   tempModuleInfo.addEventListener(ModuleEvent.READY, onReady);   tempModuleInfo.addEventListener(ModuleEvent.PROGRESS, onProgress);   tempModuleInfo.addEventListener(ModuleEvent.ERROR, one rror);   tempModuleInfo.addEventListener(ModuleEvent.SETUP, onSetup);                   tempModuleInfo.load(ApplicationDomain.currentDomain);}            private function onSetup(evt:ModuleEvent):void{                }            private function onProgress(evt:ModuleEvent):void{   msg.htmlText = "正在加载:" + Math.floor(evt.bytesLoaded / evt.bytesTotal).toString() + "%";}            private function onReady(evt:ModuleEvent):void{   var moduleInfo:IModuleInfo = evt.target as IModuleInfo;                   moduleInfo.removeEventListener(ModuleEvent.PROGRESS, onProgress);   moduleInfo.removeEventListener(ModuleEvent.READY, onReady);   moduleInfo.removeEventListener(ModuleEvent.ERROR, one rror);                   msg.htmlText = "模块加载完成";                   moduleCanvas.addChild(moduleInfo.factory.create() as DisplayObject);}            private function one rror(evt:ModuleEvent):void{   msg.htmlText = "模块加载出错!";}