Solved

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

Posted on 2010-09-11
3
1,824 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
ID: 33669175
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
ID: 33669185
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
ID: 33669313
Oh, guess I came by a bit late.

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

-V
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Include Adobe AIR libraries in Flash Builder 4 122
Tech Writing Terminology - Pane or Panel? 8 87
Create associate webpages / websites 3 80
SP to delete duplicates 15 70
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 …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

810 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