本文和大家重点讨论一下Flex模块化的概念,主要包括Flex模块化的目的和如何进行Flex模块化两大部分内容,相信本文介绍一定会让你有所收获。
Flex模块化学习总结
1.为什么要Flex模块化
Flex模块化提供了分离应用程序代码到不同的swf文件上以便减少下载时间和文件大小。使用Modules的好处是:
1.主应用程序开始时不需马上下载modules。应用程序会根据需求载入和卸载modules。
2.由于每个modules独立于其他应用程序modules,当需要改变一个modules时,你只需要重编译这个modules而不是整个应用程序。
Flex模块化可创建Flex模块化应用程序是提高Flex框架性能的重要方面,提供更多能力控制下载时间和文件大小,使用modules,你可以根据哪些可被独立载入,哪些可被其他程序使用而分离应用程序代码,
2.如何Flex模块化
2.1创建模块
基于mxml的模块,在你的工程右键->new->mxmlModule
<?xmlversionxmlversion="1.0"encoding="utf-8"?>
<mx:Modulexmlns:mxmx:Modulexmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"width="400"height="300">
</mx:Module>
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
基于as的模块
package
{
importmx.modules.Module;
publicclassGeneralextendsModule
{
publicfunctionGeneral()
{
super();
}
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
2.2Flex模块化中加载模块
2.2.1使用ModuleLoader加载;
<mx:ModuleLoaderurlmx:ModuleLoaderurl="ContactList.swf"/>
- 1.
2.2.2使用ModuleManager加载
PrivatefunctioncreationHandler():void
{
_moduleInfo=
ModuleManager.getModule('ContactList.swf'
);
_moduleInfo.addEventListener(ModuleEvent.READY,
moduleLoadHandler);
_moduleInfo.load();
}
PrivatefunctionmoduleLoadHandler(evt:ModuleEvent):void
{
canvas.addChild(_moduleInfo.factory.create()as
DisplayObject);
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
2.2.3创建弹出模块
Vargeneral:ModuleLoader
general=ModuleLoader(mx.managers.PopUpManager.
createPopUp(this,ModuleLoader));
general.url="General.swf";
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
注意:在创建弹出模块时,有时会产生:无法将mx.managers::PopUpManagerImpl@bba9941转换为mx.managers.IPopUpManager这种错误,这个时候我们需要在主程序里引入
importmx.managers.IPopUpManager;
privatevaripopUp:IPopUpManager
- 1.
- 2.
- 3.
【编辑推荐】