Following the discussion about "root" yesterday, it got me thinking about a constant problem I face.

Object-A needs to listen to events coming from objects B, C and D, but only if and when these objects actually exist. There's no guarantee that any of the objects B, C and D will be instantiated before or after A is instantiated. So, what's the proper way for A to add itself as a listener to B, C and D?

What I'm currently do is this:

   The event dispatchers (B, C, D etc) implement a singleton interface.

Within the target (A), I set up a Timer event to repeatedly check for instances of the dispatchers. Once a dispatcher is found, the target adds itself as a listener, and a pointer to the dispatcher is created so that the target can later remove itself.


I'm not very happy with this design, but it's the best that I've been able to come up with.
Thanks!
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to