flex 装载多个module出现的问题Error #1034: 强制转换类型失败

Flex模块加载错误#1034解决
本文介绍了解决Flex应用中模块加载时出现TypeError#1034错误的方法。该错误通常发生在使用多个模块并涉及Popup、Drag等功能时。文章提供了两种解决方案:一种是在主应用中声明“木偶变量”,另一种是在ModuleLoader中设置applicationDomain。

摘自http://bzhang.javaeye.com/blog/322148

TypeError: Error #1034: 强制转换类型失败:无法将 Object@1aee90b1 转换为 mx.messaging.messages.IMessage。


需求背景
通过树形菜单加载多个不同的module。
问题现象 :module页面存在拖动,Popup,Alert或者colorpicker出现错误信息:
TypeError: Error #1034: 强制转换类型失败:无法将 mx.managers::PopUpManagerImpl@7155ac1 转换为 mx.managers.IPopUpManager。
解决方案
在Application加入如下代码引用:
<!----> < mx:Script >
<! [CDATA[
import mx.managers.DragManager;
import mx.managers.IPopUpManager;

/* Createdummyvariables. */
// 避免出现:无法将mx.managers::PopUpManagerImpl@52a09a1转换为mx.managers.IPopUpManager错误
private vardragManager:DragManager;
private varpopUpManager:IPopUpManager;

//process....

]]>
</mx:Script>
问题原因分析
属于ModuleLoader shared code problem .
当Module中使用managers时(如PopUpManager,DragManager, HistoryManager等)则可能出现这个问题(当application里在loader之前没有引入这些manager的引用时)。
manager的方法是静态方法,整个应用程序中创建了一个该manager接口的singleton实例,但module仅在自己的 Application domain中使用该单例, 当多个module使用同一个单例manager且main application没有使用时,就会出现这个空对象引用问题:第一个引入某manager的module不能将该manager接口的 singleton跟其他module共享,其他module调用该Manager的方法时,应用程序不会再创建该manager接口的实例,这个 module就无法引用到该manager接口的实例,就出现了空对象引用问题.
参考资料:Flex sdk源码。

目前在Application创建了些Application范围内没有使用到的"木偶变量",从代码可读性上来说不是很好。有其他比较好的解决方案的同学麻烦请告之下,:)


posted on 2008-11-22 17:33 钩子 阅读(1118) 评论(1) 编辑 收藏 所属分类: jeeria工作笔记

<!---->

<noscript type="text/javascript"> //<![CDATA[ Sys.WebForms.PageRequestManager._initialize('AjaxHolder$scriptmanager1', document.getElementById('Form1')); Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tAjaxHolder$UpdatePanel1'], [], [], 90); //]]> </noscript>

Feedback

# re: FLEX:multiple moduleloader occur #1034 error 2008-11-24 10:14 钩子

同事推荐了个更好的办法:
在ModuleLoader 的creationComplete方法中加入如下代码:
moduleLoader.applicationDomain = ApplicationDomain.currentDomain;
就可以在Application里切换多个module而不需要在Application里明文引用单例manager声明。比我上面所说的方法更好的能解决问题而且,代码可读性更好。
另外,推荐在moduleloader做切换的时候,加上:
moduleLoader.unloadModule再做moduleLoader.loadModule().

在这里做个小记。

*** Using Compiler &#39;&#39;, folder: &#39;C:\Keil_v5\ARM\ARMCLANG\bin\&#39; Rebuild target &#39;Target 1&#39; Error instantiating RTE components Error #543: Device () not found, pack &#39;&#39; is not installed Error #541: &#39;Renesas::Flex Software:Build Configuration&#39; component is missing (previously found in pack &#39;Renesas.Project Content&#39;) Error #541: &#39;Renesas::Flex Software:Components:ra&#39; component is missing (previously found in pack &#39;Renesas.Project Content&#39;) Error #541: &#39;Renesas::Flex Software:Generated Data&#39; component is missing (previously found in pack &#39;Renesas.Project Content&#39;) Error #541: &#39;Renesas::Flex Software:Linker Script&#39; component is missing (previously found in pack &#39;Renesas.Project Content&#39;) Error #540: &#39;Renesas::Flex Software:RA Configuration:1.0.0&#39; component is not available for target &#39;Target 1&#39; Target not created. Build Time Elapsed: 00:00:02 *** Error - Project: &#39;zf_ra_motherboard_demo&#39;, Target: &#39;Target 1&#39; - *** Device: &#39;R7FA8D1BH&#39;, Vendor: &#39;Renesas&#39;, Dcore: &#39;Cortex-M85&#39; *** Cause - Dcore &#39;Cortex-M85&#39; is not supported causing invalid Compiler/Debug/Flash setup. Error instantiating RTE components Error #543: Device () not found, pack &#39;&#39; is not installed Error #541: &#39;Renesas::Flex Software:Build Configuration&#39; component is missing (previously found in pack &#39;Renesas.Project Content&#39;) Error #541: &#39;Renesas::Flex Software:Components:ra&#39; component is missing (previously found in pack &#39;Renesas.Project Content&#39;) Error #541: &#39;Renesas::Flex Software:Generated Data&#39; component is missing (previously found in pack &#39;Renesas.Project Content&#39;) Error #541: &#39;Renesas::Flex Software:Linker Script&#39; component is missing (previously found in pack &#39;Renesas.Project Content&#39;) Error #540: &#39;Renesas::Flex Software:RA Configuration:1.0.0&#39; component is not available for target &#39;Target 1&#39;
最新发布
05-09
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值