Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

618 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