3 Replies Latest reply on Aug 21, 2007 9:35 PM by Chris Ivey

    Custom Event Scope Issue?

    cayennecode Level 1
      I think I need I might need to create an Event member for the Dispatching Object, but am not sure. Any idea what's missing from the example code below?

      Base Class:
      import flash.events.*;

      private function init():void
      {
      _Data = new Data();
      _Data.addEventListener(Data.DATA_INIT, dataInit);
      }

      private function dataInit(e:Event):void
      {
      trace('dataReceived');
      }

      Object Class:
      import flash.events.*;
      public class Data extends EventDispatcher
      {
      public static const DATA_INIT:String = "DATA_INIT";
      .....
      private function someFunction()
      {
      dispatchEvent(new Event(Data.DATA_INIT));
      }
        • 1. Re: Custom Event Scope Issue?
          cayennecode Level 1
          My goodness this is tormenting my soul.

          I've tried adding of 1 second before dispatching the event and the base class still isn't receiving notification.
          • 2. Custom Event Scope Issue?
            cayennecode Level 1
            I found the problem.

            I was calling the function from another class. For some reason when I do this, the EventListener isn't called. But when I call the dispatchEvent function from within the EventDispatcher Object class, it works.

            hope that makes sense, I'm trying to breeze through this quickly.

            I suppose this morphs my question/problem into, why does this happen?
            • 3. Re: Custom Event Scope Issue?
              Chris Ivey
              I am having virtually the same problem with event dispatch. I know what the problem seems to be (though it makes no sense), but I don't know of a good workaround.

              If events are dispatched from a static class or from the base class, they never get beyond the target phase, so they are never propagated out of the scope of the class.

              I suppose that you could instantiate a singleton, and dispatch your events from that using a method call, but that seems REALLY kludgy. Does anyone know of a better solution?