In other words:
Create a Controller class before creating any other classes.
Any instances that need to know when potential event dispatchers are
created should listen to the Controller class.
When dispatchers are created, the Controller class should dispatch
an event.
This way I won't need to use a Timer to repeatedly look for the dispatchers.
Merrill, Jason wrote:
If an instance of those classes has been created, then it will eval to
true, otherwise it will be null, so this should work for that part of
the problem:
if(_myinstance) _myInstance.addEventListener(myEvent, myHandler);
However, if you're creating "A" after "B", "C", and "D", then you'll
want to call the code above from say, a Controller class whenever "A" is
created. Once "A" is created, then that's a trigger to add the
listeners to the other classes if they exist. Make sense?
Jason Merrill
Bank of America Global Learning
Learning & Performance Solutions
Join the Bank of America Flash Platform Community and visit our
Instructional Technology Design Blog
(inote: these are for Bank of America employees only)
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Andrew
Sinning
Sent: Tuesday, February 23, 2010 10:04 AM
To: Flash Coders List
Subject: [Flashcoders] accessing event dispatchers in a
loosely-coupled,modular design
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
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders