惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
Hugging Face - Blog
Hugging Face - Blog
L
LINUX DO - 热门话题
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
D
Docker
C
Cyber Attacks, Cyber Crime and Cyber Security
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
T
Tenable Blog
P
Privacy International News Feed
Google DeepMind News
Google DeepMind News
小众软件
小众软件
Cisco Talos Blog
Cisco Talos Blog
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
A
Arctic Wolf
C
Cybersecurity and Infrastructure Security Agency CISA
C
Cisco Blogs
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
The Hacker News
The Hacker News
Project Zero
Project Zero
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threatpost
V
Visual Studio Blog
The GitHub Blog
The GitHub Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
Jina AI
Jina AI
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
MongoDB | Blog
MongoDB | Blog
U
Unit 42
Scott Helme
Scott Helme
A
About on SuperTechFans
WordPress大学
WordPress大学
F
Fortinet All Blogs
大猫的无限游戏
大猫的无限游戏
G
GRAHAM CLULEY
Latest news
Latest news
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Schneier on Security

博客园 - otto

java web应用程序的热部署 自定义真正可重用的Flex组件 hp的笔记本真垃圾 关于fusionchart的使用 RIA 过渡期的选择 flex3很强大 完美封装了fusionchart eclipse 突然不能自动编译了 FusionCharts 的中文问题 Spring 依赖的Jar包简介 java5, java6 的新特性 我的firefox插件,留此存照 Spring AOP中文教程 [转]J2EE架构的6个最佳实践 使用struts+spring+hibernate组装你的web应用架构 Java开源项目Hibernate包作用详解(转) oracle中的树型查询 blog与生活 尝试
合理使用Module分割项目以及对Module的使用
otto · 2010-12-16 · via 博客园 - otto

转自:http://bbs.airia.cn/thread-2811-1-1.html

这篇介绍module使用的随笔写得不错。

现在说说Module,这篇教程代码不是最重要的,怎么样合理的使用Module以及注意的问题才是关键,所以建议大家注意下面红色语句。Module,可以将我们的项目按需划分为N个模块,在编译时将项目编译为主文件以及N个module的swf。Module基本上可以分为两种:

  1. 完整的Module,可以被外部app所使用 -- 会将所有涉及到的引用编译到module中,主文件的体积得到缩减,但是Module本身的体积可能会很大,比如Module和主程序都应用了对象C,那对象C会被编译到主程序以及Module中,这样Module的体积就会很大。 
  2. 关联到主程序的Module -- 比如Module和主程序都应用了对象C,那对象C会只编译在主程序中,从而减小Module的体积。我今天主要讲这一种Module,也是我们最常用到的。

了解了Module的种类,再简单说说使用Module要注意的地方。

  1. 绝对不能在Module以外的地方直接引用Module中的对象。这样Module会被编译到引用它的模块中去,如果从主程序中引用,那么Module就实际上没有效果了。
  2. 既然不能引用,那么建议对Module对象的使用用接口实现。在Module中实现接口方法,在外部使用这个接口不会导致Module被误编译。
  3. Module可以引用主程序中的东西,但是不要引用其他Module中的东西。

Module可以做什么呢?我主要将Module用于以下下两种情况

  1. 缩减主程序的体积,点击Module功能块时加载Module.
  2. 再入主程序后在用户感觉不到的情况下预加载剩下的Module.

现在讲正题,在demo中我这样表现Module的使用。(为了体现Module的意义,主程序生成的大小是原始flex大小248K, module内嵌了两张图片是674K)

  1. 如何创建Module.
  2. 主程序中点击按钮加载Module PictureWindow.
  3. 加载完毕后将模块添加到Box中,并通过接口调用PictureWindow中的方法setSelectIndex()设置显示的图片。

1. 如何创建Module.

可以通过New --> MXML Module -->Optmize for applicaiton --> OK 或者修改任意的已经创建好的Container组建(比如Canvas, panel)标签为Module,再或者继承Module的As class。

之后确保“鼠标右键项目”--> Property --> Flex Module  中有这个Module,没有的话点Add --> 选择Module的mxml或as文件 -->Optmize for applicaiton -- > OK

2. 主程序中点击按钮加载模块PictureWindow.

这里我使用了ModuleManager来动态加载需要的Module。这比ModuleLoder要灵活的多。

private function loadModule():void{
m
= ModuleManager.getModule("PictureWindow.swf"); //设置Module地址,地址是编译后swf在bin中的位置
//设置事件监听
m.addEventListener(ModuleEvent.READY,loadReady);
m.addEventListener(ModuleEvent.PROGRESS,
loading);
m.addEventListener(ModuleEvent.ERROR,loadError);
m.load();
//加载Module
}

3. 加载完毕后将模块添加到Box中,并通过接口调用PictureWindow中的方法setSelectIndex()设置显示的图片。

PictureWindow实现了PictureWindowInterface接口,其中暴露了setSelectIndex方法。再次强调不要直接使用Module对象,如果我们不注意写成var window:PictureWindow = e.module.factory.create() as PictureWindow,那整个Module就前功尽弃了

 //Module加载完成
private function loadReady(e:ModuleEvent):void{
//将Module对象转换为PictureWindowInterface
var window:PictureWindowInterface = e.module.factory.create() as PictureWindowInterface
this.box.addChild(window as DisplayObject);
window.setSelectIndex(
1); //通过Interface调用Module中的方法
}

好了,Module的使用就写这么多,看到这里你应该也可以创建自己的Module了,对于ModuleManager和IModuleInfo 中详细的内容,大家可以查阅Flex帮助。

代码下载请看原文。