Solved

Flex 3: Getting Error: Error #2094: Event dispatch recursion overflow

Posted on 2010-09-11
3
1,799 Views
Last Modified: 2013-11-11
I'm not sure I understand why I'm getting the error:

Error: Error #2094: Event dispatch recursion overflow

All I'm trying to do is capture the close event of a TitleWindow popup so that I could do something about that.

Here is the main MXML application:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">

  <mx:Script>
  <![CDATA[
    import mx.managers.PopUpManager
    import mx.containers.TitleWindow;
    import mx.events.CloseEvent;
    import TestPopUp;
 
    private var _window:TitleWindow;
      
      private function showPopUp(event:Event):void
    {
            _window = TitleWindow(PopUpManager.createPopUp(this, TestPopUp));
            _window.addEventListener(CloseEvent.CLOSE, closeHandler);
    }

    private function closeHandler(event:CloseEvent):void
    {
            // I WANT TO DO SOMETHING HERE IN RESPONSE TO THE
            // POPUP's CLOSE EVENT.
    }
   
   ]]>
  </mx:Script>

  <mx:Button id="button" label="Show Popup" click="showPopUp(event)" />

</mx:Application>


And here is the code for the popUp MXML component:


<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
            showCloseButton="true" close="closeEventHandler(event)"
            title="Sample PopUp">
            
      <mx:Script>
        <![CDATA[
          import mx.managers.PopUpManager;
          import mx.events.CloseEvent;
          
          private function closeEventHandler(event:CloseEvent):void
          {
                  dispatchEvent(event); // THE ERROR IS OCCURRING HERE
                  PopUpManager.removePopUp(this);
          }
        ]]>
  </mx:Script>

      <mx:VBox width="300" height="300" backgroundColor="red" />
</mx:TitleWindow>

I'm not sure I understand where the recursion could even occur. The close event of the PopUp is dispatching an event, and then it's removed. So far, only one event has been dispatched, and I was expecting the main MXML application to catch that and invoke the closeHandler() method.

So can someone please help me understand how any recursion could occur here? Also, can anyone show me how to achieve what I'm trying to do here?
0
Comment
Question by:elepil
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
Antonio Estrada earned 500 total points
Comment Utility
Haven't tried it, but sounds to me that you're re-dispatching the same event, thus the listener grabs the same event over and over, thus creating a recursion overflow.

Instead of
dispatchEvent(event);

Try this:
dispatchEvent(new CloseEvent(CloseEvent.CLOSE));

If that doesn't work (which might be the case since the event is the same, albeit a new instance of it), try creating a new event.

_window.addEventListener("testEvent", closeHandler);

private function closeHandler(event:Event):void

dispatchEvent(new Event("testEvent"));

The last three lines are obviously a quick&dirty solution, and if you're really going to use custom events, I recommend creating a custom event with it's own class, just to keep the code tidy. But then again, these might not be needed.

Good luck!

-V
0
 

Author Closing Comment

by:elepil
Comment Utility
I already figured this out but forgot to close this, but thanks for responding, so you get the points.

You are right. I was getting that recursive error because I was dispatching a CloseEvent.CLOSE within the close handler I defined at the root tag. I did get around this problem though.
0
 
LVL 18

Expert Comment

by:Antonio Estrada
Comment Utility
Oh, guess I came by a bit late.

Glad you got it sorted, and thanks for the points :)

-V
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now