Custom Event Scope Issue?

Custom Event Scope Issue?

Post by cayennecod » Thu, 12 Jul 2007 02:02:13


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));
}
 
 
 

Custom Event Scope Issue?

Post by cayennecod » Thu, 12 Jul 2007 02:24:17

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.

 
 
 

Custom Event Scope Issue?

Post by cayennecod » Thu, 12 Jul 2007 02:52:40

I found the problem.

I was calling the dispatchEvent 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.
 
 
 

Custom Event Scope Issue?

Post by Chris Ive » Thu, 23 Aug 2007 13:35:42

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?