最近用到了模块部分,开始研究
谁料昨天卡在了模块高宽设置上一个下午,找了些资料,解决了.
问题:
当模块设置width及height为100%时,加载到父级容器后会发现模块并不能自动填充,即使ModuleLoader的width和height均设置为100%
若在模块中只加入Canvas测试,发现加载后其高宽值均为0.
解决:
(方法1)直接在模块参数中加入percentWidth=”100″ percentHeight=”100″
例:
(方法2)在模块加载完成后设置模块percentWidth,percentHeight属性值为100
例子见源文件
部分源码说明:
设置ModuleLoader高宽为适应100%并注册ready,resize,error事件
ready="readyModule(event);"
resize="resizeHandler(event);"
error="errorModule(event)"/>
ModuleLoader的Ready事件:
重设模块的percentWidth和percentHeight.如果模块按方法1进行设置后,这两个可以不设置
private function readyModule(event:ModuleEvent):void{
var tmpModule:ModuleLoader = event.target as ModuleLoader;
var Mchild:* = tmpModule.child;
Mchild.percentWidth = 100;
Mchild.percentHeight = 100;
}
演示文件及源代码:
Demo(MainApp.swf)
DemoSource(FLEX_Module_Resize.zip)
编译过程
产生类库列表
[color=Blue]mxmlc -link-report=report.xml MainApp.mxml
编译主程序
[color=Blue]mxmlc MainApp.mxml
编译模块
[color=Blue]mxmlc -load-externs=report.xml MyModule.mxml
编译过程原文档:
http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&file=modular_083_4.html
参考资料:http://livedocs.adobe.com/flex/201
P.S.
ADOBE关于模块化开发的例子和文档: http://blogs.adobe.com/flexdoc/modules/
FLEX错误代码WIKI: http://editthis.info/flexerrorcodes/Main_Page
Flash版:http://judahfrangipane.com/errorsearch/ErrorLookup.html

这个我试了下,果然是被压缩了。换成TitleWindow也是同样的问题。控制模块高度和位置也无效,也许是个BUG,
等待修复。或者是模块在FLEX3下有新的使用方法,呵呵
[Reply]
请教问题:这是FLEX3做的程序,切换模块A,B的时候,两个模块高度都被压缩。
在FLEX2下就正常。
http://blog.sina.com.cn/s/blog_49e5461d01000fra.html
[Reply]