使用 PureMVC 转换检索到的 Mediator 作为其正确的类返回 null
我有一个为导航页面注册的中介器:
facade.registerMediator(new NavPageMediator(viewComponent));
我正在尝试在另一个页面上检索该中介器,如下所示:
var navPageMediator:NavPageMediator = facade.retrieveMediator(NavPageMediator.NAME) as NavPageMediator;
但是,该语句返回 null
。如果我尝试使用 NavPageMediator(facade.retrieveMediator(NavPageMediator.NAME)) 语法来转换它,我会得到一个
TypeError: Error #1034: Type Coercion failed: cannot convert com.website.mvc.view.page::NavPageMediator@237560a1 to com.website.mvc.view.page.NavPageMediator.`
我一生都无法理解为什么 NavPageMediator@237560a1
无法转换为 NavPageMediator
,也无法理解在注册中介器和检索它之间发生了什么造成了这个。特别是因为 trace(new NavPageMediator() as NavPageMediator);
返回 [object NavPageMediator]
。
顺便说一句,这可能是我的问题的一部分,我不明白对象末尾的@hash是什么(@237560a1
)。它只是该类实例的内部标识符吗?
编辑: 留下一些重要信息:我在其中实例化和注册中介器的 SWF 与我尝试在其中检索它的 SWF 是分开的。
I have a mediator that I've registered for a navigation page:
facade.registerMediator(new NavPageMediator(viewComponent));
I'm trying to retrieve that mediator on another page like so:
var navPageMediator:NavPageMediator = facade.retrieveMediator(NavPageMediator.NAME) as NavPageMediator;
However, that statement returns null
. If I try to cast it using the NavPageMediator(facade.retrieveMediator(NavPageMediator.NAME))
syntax instead, I get a
TypeError: Error #1034: Type Coercion failed: cannot convert com.website.mvc.view.page::NavPageMediator@237560a1 to com.website.mvc.view.page.NavPageMediator.`
I can't, for the life of me, understand why NavPageMediator@237560a1
would be unable to convert to NavPageMediator
, nor what happened in between registering the mediator and retrieving it that caused this. Especially since trace(new NavPageMediator() as NavPageMediator);
returns [object NavPageMediator]
.
Incidentally, and this may be part of my problem, I don't understand what the @hash at the end of the object is (@237560a1
). Is it simply an internal identifier for that class instance?
Edit:
Left a bit of important info: The SWF in which I instantiate and register the mediator is separate from the SWF in which I try to retrieve it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
想通了。事实证明这是一个ApplicationDomain问题。将两个 SWF(注册者和检索者)分配到同一域解决了该问题。
此外,我非常确定类名末尾的 @hash 是对该类所属的 ApplicationDomain 的内部引用。所以
NavPageMediator@237560a1
与NavPageMediator
位于不同的域中(为什么第二个域上没有哈希,我仍然不确定;这会让事情变得更清楚一点) )。Figured it out. It turned out to be an ApplicationDomain issue. Assigning both SWFs (the registrant and the retriever) to the same domain solved the issue.
Additionally, I'm pretty sure the @hash at the end of the class name is an internal reference to the ApplicationDomain to which the class belongs. So
NavPageMediator@237560a1
was in a different domain thanNavPageMediator
(why there was no hash on the second one I'm still not sure; that would have made things a bit clearer).