PureMVC MultiCore报错 multitonKey for this Notifier not yet initialized!

multitonKey for this Notifier not yet initialized!

官方解释是:

As noted in the release notes for MultiCore, you cannot access the facade from within the constructor of a Notifier subclass. The first chance you get to access the Facade is in initializeNotifier. But you could instead wait until onRegister. If you wait until onRegister, you don't have to call super at all.

And although this represents a slight departure from the Standard version practices, it actually sheds light on the fact that calling the facade inside the constructor of a Notifier instance is not really the best practice anyway. Of course onRegister has only just appeared in 2.0 and so the fact that it is the more appropriate place for facade access is just now becoming clear.

Why is onRegister the better place? Because interaction with the Facade should only happen when a Mediator or Proxy is registered, and therefore accessible by other actors via the Facade. For instance a Mediator's interaction with the Facade could lead to a Notification that the Mediator needs to hear. But if it is not yet registered, it could not be notified. Or if a Proxy interacts with the Facade, it could result in another actor trying to retrieve that Proxy, and if it is not yet registered, it cannot be retrieved.

Make sense?

也就是说,在所有的订阅者的构造器上,不要访问facade。访问了也白搭。

官方建议在onRegister方法上,来访问facade。

例如:

override public function onRegister():void
 {
	 var avatarPanel:AvatarPanel = new AvatarPanel();
	facade.registerMediator(new AvatarMediator(avatarPanel));
	controlBarPanel.avatarPanel = avatarPanel;
 }

 

还有

 

override public function onRegister():void
{
	sendNotification(ApplicationFasade.DATALOADED);
}

 

出现这个问题把send的代码写在onRegister()函数里即可

你可能感兴趣的:(this)