flex4 module 管理类

flex4.1 actionscript3

代码如下:

 

 

package modulemanager

{

import flash.utils.Dictionary;

import mx.events.ModuleEvent;

import mx.modules.IModule;

import mx.modules.IModuleInfo;

import mx.modules.Module;

import mx.modules.ModuleManager;

import spark.components.Group;

/**

* module管理类

* @author yinlm

* */

 

public class ModuleLoaderUtil

{

public function ModuleLoaderUtil(modulecontainer:Group = null)

{

this.modulecontainer = modulecontainer;

}

private var modulecontainer:Group;

/**

* 当前module信息接口

* */

private var currentModuleInfo:IModuleInfo;

/**

* 当前module

* */

private var currentModule:Module;

/**

* 当前module的地址

* */

private var currentModuleUrl:String = "";

/**

* 使用Dictionary对加载策略为cache的Module持有引用,

* 当第二次需要使用该Module时,直接返回缓存对象,而不再创建新的对象

*/

private var moduleCacheDict:Dictionary = new Dictionary(true);

public function handleLoadModule(moduleUrl:String):void

{

if(currentModuleUrl == moduleUrl){

return;

}

if(currentModule != null){

destroyModule();

}

if(moduleCacheDict[moduleUrl] != null) {

currentModule = moduleCacheDict[moduleUrl];

modulecontainer.addElement(currentModule);

currentModuleUrl = moduleUrl;

}else{

currentModuleInfo = ModuleManager.getModule(moduleUrl);

currentModuleUrl = moduleUrl;

currentModuleInfo.addEventListener( ModuleEvent.READY, handleModuleLoad );

currentModuleInfo.load();

}

}

private function handleModuleLoad( evt:ModuleEvent ):void

{

currentModule = currentModuleInfo.factory.create() as Module;

modulecontainer.addElement(currentModule);

}

private function destroyModule():void {

if(moduleCacheDict[currentModuleUrl] == null){

moduleCacheDict[currentModuleUrl] = currentModule;

}

modulecontainer.removeElement(currentModule);

currentModule = null;

}

}

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值