Solved

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

Posted on 2010-09-11
3
1,860 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

717 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