Any displayobject can listen for events on the top-level displayobject
in capture phase and find out about what is being sent to other
displayobjects.  However, it sounds like there is some other criteria
that decides whether to dispatch an event.  Whereever that code is is
potentially the thing that should dispatch the event

 

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of thirtyfivemph
Sent: Wednesday, February 13, 2008 2:26 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Broadcasting event to all objects on display list

 

Is it possible to dispatch an event to all objects on the display
list? In my particular case, I'd like to have some additional
"enter_frame" like events that all display objects receive (but I
don't want it tied to enter_frame because the event doesn't
necessarily happen every frame).

My current solution is that each object add an event listener to a
central object, but I'm not thrilled with this coupling (though it may
be unavoidable).

I'd love to be able to do this:

- In the constructor for my DisplayObject-based class I call
addEventListener("myEvent", handleMyEvent);

- Somewhere higher up in the display list hierarchy I call
dispatchEvent(new Event("myEvent"));

I know this isn't quite how the event system works, and this may be an
excellent reason to have some kind of singleton EventRouter object
that deals with global events. But in my setup, whether or not an
object should receive an event (and which particular occurrence of the
event at that) is determined by the display list hierarchy.

Another option I've looked at is each object listening to its parent,
and when it receives the event is re-dispatches it to all of its
children. This works, it does allow me to create an event at the top
of the hierarchy, dispatch it, and have it flow to all the children.
But it just feels like there's a better way with Flash's native event
system... though there may not be.

Any suggestions are appreciated!

Troy.

 

Reply via email to