使用 PopUpManager 执行事件的最佳方式?

发布于 2024-10-31 08:08:59 字数 455 浏览 5 评论 0原文

如果我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一曲琵琶半遮面シ 2024-11-07 08:08:59

请尝试此操作

var popup:SomePopup = PopUpManager.createPopup(this, SomePopup, true) as SomePopup;
popup.addEventListener(CloseEvent.CLOSE, onClose);

并确保在弹出窗口关闭时删除该偶数侦听器。

Try this instead

var popup:SomePopup = PopUpManager.createPopup(this, SomePopup, true) as SomePopup;
popup.addEventListener(CloseEvent.CLOSE, onClose);

And make sure you remove that even listener when the popup closes.

孤独难免 2024-11-07 08:08:59

如果您想捕获顶部的冒泡事件,可以将事件侦听器添加到 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.

只为守护你 2024-11-07 08:08:59

我对 Mate 比 Cairngorm 更熟悉,但在这种情况下我所做的是用模型备份我的弹出窗口并从模型中分派事件。由于模型和主应用程序位于同一级别,因此主应用程序可以听到事件。

更新:

这是一个粗略的示例。

在我的 MainMap.mxml 中,我创建了演示模型的一个实例并将其注入到我的弹出窗口中。

<EventHandlers type="{ FlexEvent.PREINITIALIZE }">
  <ObjectBuilder generator="{ MyPopUpPresentationModel  }" constructorArguments="{ scope.dispatcher }"/>
</EventHandlers>

<Injectors target="{ MyPopUp }">
    <PropertyInjector targetKey="model" source="{ MyPopUpPresentationModel }"/>
</Injectors>

MyPopUp.mxml 中,我有一个模型的实例。

<fx:Script>
  <![CDATA[
    [Bindable] public var model:MyPopUpPresentationModel;
  ]]>
</fx:Script>

这是MyPopUpPresentationModel.as

package
{
  private var dispatcher:IEventDispatcher;
  public function DigitalTagTrackingPresentationModel(target:IEventDispatcher)
  {
    this.dispatcher = target;
  }

  public function dispatchMyCustomEvent():void
  {
    dispatcher.dispatchEvent(new Event("MyCustomEvent"));
  }
}

当您从 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.

<EventHandlers type="{ FlexEvent.PREINITIALIZE }">
  <ObjectBuilder generator="{ MyPopUpPresentationModel  }" constructorArguments="{ scope.dispatcher }"/>
</EventHandlers>

<Injectors target="{ MyPopUp }">
    <PropertyInjector targetKey="model" source="{ MyPopUpPresentationModel }"/>
</Injectors>

And In MyPopUp.mxml I have an instance of my model.

<fx:Script>
  <![CDATA[
    [Bindable] public var model:MyPopUpPresentationModel;
  ]]>
</fx:Script>

Here's MyPopUpPresentationModel.as.

package
{
  private var dispatcher:IEventDispatcher;
  public function DigitalTagTrackingPresentationModel(target:IEventDispatcher)
  {
    this.dispatcher = target;
  }

  public function dispatchMyCustomEvent():void
  {
    dispatcher.dispatchEvent(new Event("MyCustomEvent"));
  }
}

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!

万水千山粽是情ミ 2024-11-07 08:08:59

在弹出窗口中,您可以使用:
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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文