Flex 事件侦听器回调未触发
也许你可以帮我指出正确的方向。在我们的应用程序中,我定期注意到特定的事件处理程序没有触发。 99% 的时候,它工作得很好,但是,时不时地,它就会死掉。我怎样才能知道发生了什么? DispatchEvent() 是否没有发生/工作?我的听众还在听吗?是否有其他东西捕获了该事件,但没有将其传递以便“正确的”侦听器可以到达它?
这是一些代码......
这是实际代码的精简版本,但我认为我没有删除任何重要的内容。我认为关键是我们启动参数对话框,然后开始监听关闭事件。然后,我们展示参数对话框关闭函数。失败时会发生的情况是,永远不会生成跟踪消息“caught close event..”,因此根本不会调用 closeHandler。
我没觉得那里有什么不妥之处,你觉得呢?
那么,我可以使用什么工具来追踪这个小家伙呢?
谢谢!
Maybe you can help point me in the right direction on this. In our app, I am periodically noticing that a particular event handler is not firing. 99% of the time, it works fine, but, every so often, it just dies. How can I find out whats happening? Is the DispatchEvent() not happening/working somehow? Is my listener still listening? Did something else catch the event, and not pass it along so that the 'right' listener can get to it ?
Here's a little bit of the code...
Thats a somewhat pruned down version of what the real code is, but I don't think I trimmed out anything important. The key, as I see it is that we fire up the params dialog, then start to listen for the closed event. Then, we show the param dialogs close function. What happens when it fails is that the trace message "caught close event.." is never generated, and, consequently, the closeHandler is not getting called at all.
I don't see anything out of place there, do you?
So, what tools are at my disposal to track this little bugger down?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在处理从组件内部的显示列表中删除组件的操作。您可以在实际删除对象之前分派 CLOSE 事件,但它很可能在对象已被删除时到达。这是由于事件的异步性质造成的。这意味着,每隔一段时间,当事件到达时,处理事件的函数就不再存在。当然,如果您使用弱引用。
解决方案
现在解决这个问题:
如下所示:
You're handling the removal of your component from the displaylist from inside the component. You dispatch the CLOSE event before you actually remove it, but it may very well arrive when the object is already removed. That's due to the asynchronous nature of events. This means that every once in a while the function that handles the event, simply doesn't exist anymore when the event arrives. Certainly if you use a weak reference.
solution
Now to solve the issue:
PopUpManager.removePopUp(this)
, since 'this' doesn't refer to the component, but to the closure itself.like this: