Hey guys,
Sorry if this has been asked before. Can’t find it with the search.
Is it possible to listen for bubbled events on the stage?
Right now I have this working:
myClass.addEventListener(“customEvent”, eventHandler);
but
stage.addEventListener(“customEvent”, eventHandler);
or
addEventListener(“customEvent”, eventHandler);
Don’t work.
Essentially. I have a customEvent that multiple objects can dispatch, and I want the stage to be able to listen to all of them at once.
From within the class I’m calling:
dispatchEvent(new Event(“testEvent”, true));
I’d appreciate any help, thanks.
Ok I figured out what was wrong. I kept searching and found this:
http://www.ultrashock.com/forums/actionscript/as3-bubbling-only-for-displayobjects-94281.html
By the looks of things events only bubble up if they’re on the display list.
My class was making the dispatch before it was on my display list. The problem is that some of my objects aren’t on the display list at all.
Right now my only solution is to listen to each of the objects manually, but that really complicates things and leads to GC headaches.
Anyone have any ideas?
Ok, hopefully this will be my last reply to my own message
My current solution to the problem is to create a singletonClass
See:
In ActionScript 3, class constructors can only be set to public, which leaves AS3 developers without a clear way to implement the Singleton design pattern. Luckily, there are a couple ways of faking Singleton functionality. Both solutions are kind of...
I pass the singleton a pointer to my eventHandler class.
Then I have all my subclasses call the Singleton which in turn calls the eventHandler.
Hehe, EASY!!! Now please excuse me as I swallow my tongue in a fit of insanity.
dail
May 22, 2008, 8:53pm
4
The static event dispatcher class on his site is nice also…