开发者

Flex Event Listener Callback Not Firing

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' liste开发者_StackOverflowner can get to it ?

Here's a little bit of the code...

Flex Event Listener Callback Not Firing

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!


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:

  • you could handle the close event outside of your component
  • if you want to keep the handler inside the component, you could remove the component in the eventhandler. Keep in mind that inside that closure you can not use PopUpManager.removePopUp(this), since 'this' doesn't refer to the component, but to the closure itself.
  • you could not use a weak reference, but that's not a very good idea, since your component won't be garbagecollected because of that. That is unless you remove the event listener manually from within the closure,

like this:

var closeHandler:function = function(e:CloseEvent):void {
    trace("...");
    var p:Params = e.currentTarget as Params;
    p.removeEventListener(CloseEvent.CLOSE, closeHandler);

    /* other code that you want to execute in the closure */
}

var p:Params = PopUpManager.createPopUp(myApp, Params, true) as Params);
p.addEventListener(CloseEvent.CLOSE, closeHandler);
PopUpManager.centerPopUp(p);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜