使用 PopUpManager 执行事件的最佳方式?
如果我使用 PopUpManager 添加一个子项,并且我从该子项调度一个事件,则气泡似乎不会冒泡到我的应用程序(主应用程序)的顶部。
例如:
PopUpManager.addPopUp( popup, parentApplication as Application, false );
然后在弹出窗口中,我这样做:
dispatchEvent( new Event( "testEvent", true ) );
我在parentApplication(根.mxml)中有一个用于“testEvent”的事件监听器,但它从未触发。因此,我一直在 ModelLocator 上调度事件并侦听事件(使用 cairngorm)。这显然并不理想,因为在很多情况下我必须手动确保删除事件侦听器。
有什么想法吗?
谢谢!
If I am using the PopUpManager to add a child, and I dispatch an event from that child, the bubbles don't seem to bubble to the top of my application (main application).
For instance:
PopUpManager.addPopUp( popup, parentApplication as Application, false );
Then in the popup, I do:
dispatchEvent( new Event( "testEvent", true ) );
I have an eventListener in parentApplication (root .mxml) for "testEvent", but it never fires. Because of this, I have been dispatching events and listening for events on the ModelLocator (using cairngorm). This obviously is not ideal, because I have to manually make sure I remove the event listeners in a lot of cases.
Any ideas?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
请尝试此操作
并确保在弹出窗口关闭时删除该偶数侦听器。
Try this instead
And make sure you remove that even listener when the popup closes.
如果您想捕获顶部的冒泡事件,可以将事件侦听器添加到 FlexGlobals.topLevelApplication.systemManager。希望有帮助。
If you want to catch bubbling events at the top, you can add your event listener to FlexGlobals.topLevelApplication.systemManager. Hope that helps.
我对 Mate 比 Cairngorm 更熟悉,但在这种情况下我所做的是用模型备份我的弹出窗口并从模型中分派事件。由于模型和主应用程序位于同一级别,因此主应用程序可以听到事件。
更新:
这是一个粗略的示例。
在我的 MainMap.mxml 中,我创建了演示模型的一个实例并将其注入到我的弹出窗口中。
在 MyPopUp.mxml 中,我有一个模型的实例。
这是MyPopUpPresentationModel.as。
当您从 MyPopUp.mxml 调用
model.dispatchMyCustomEvent();
时,它将使用演示模型调度程序的范围调度事件,该调度程序与父级处于同一级别应用。我希望这有帮助!I'm more familiar with Mate than Cairngorm, but what I do in this situation is to back up my pop up with a model and dispatch the events off of the model. Since the model and the main application sit at the same level, the main application can hear the events.
Update:
Here's a rough example.
In my MainMap.mxml I create an instance of the presentation model and inject it into my popup.
And In MyPopUp.mxml I have an instance of my model.
Here's MyPopUpPresentationModel.as.
When you call
model.dispatchMyCustomEvent();
from MyPopUp.mxml it will dispatch the event using the scope of the presentation model's dispatcher which will be at the same level as the parent application. I hope this helps!在弹出窗口中,您可以使用:
Application.application.dispatchEvent,只要你的监听器本身附加到Application.application。
实际上,我不太喜欢在 Application.application 上进行调度,因为它降低了组件模型的可重用性,但在紧要关头它确实有效。
In your popup, you can use:
Application.application.dispatchEvent, as long as you listener itself is attached to Application.application.
I'm actually not a big fan of dispatching on Application.application, because it reduces the reusability of the component model, but in a pinch it does work.