?
Solved

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

Posted on 2010-09-11
3
Medium Priority
?
1,869 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa‚Ķ
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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).
Suggested Courses

800 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