2 Replies Latest reply on Apr 7, 2008 9:21 AM by ntsiii

    Event Listeners

    Cameron74
      Does anyone know why event listeners don't seem to work if they event is dispatched using creationComplete?

      The listener just never gets the event.

      Any thoughts appreciated :)

      btw I am using the addEventListener on the object that I want to listen. The code works if the event is dispatched via a click event.
        • 1. Event Listeners
          slaingod Level 1
          This is probably because you have no way to listen to that event until you finish creating it.

          Specifically, assuming your TestPanel is in TestPanel.mxml, somewhere else you must have:

          <MyViews:TestPanel id="tp" />

          And then you must also be doing:
          tp.addEventListener("EventTest", onEventTest);

          My assumtion is that a) you aren't adding the listener to the tp at all, or b) that there is no way to add a listener until initialzation is complete.

          You can easily (quick and dirty) resolve this by using this.parentApplication.dispatchEvent("EventTest") in your test() method, and
          this.parentApplication.addEventListener("EventTest, "onEventTest");
          in your catching view. Otherwise you will need to create a Custom event that exists outside of either the panel or the parent, and use that for dispatch/listening.

          (You could also do it like this.addEventListener and this.parent.dispatchEvent(..) in test().)


          • 2. Re: Event Listeners
            ntsiii Level 3
            Or try using callLater(). Just a guess, I havent used this to delay event dispatching, but it is worth a try.

            Tracy