This content has been marked as final. Show 2 replies
There are two ways you can listen to events.
1. Register for events on the object instance which is dispatching the event. That is if object2 is dispatching an event, then you should have object2.addEventListener().. Events depend on the object instances.
2. Events can be bubbled. This means you can register for an event dispatched by object2 on its parent. lets say object1 is parent of object2 and the event which is dispatched has bubbles property to true then object1.addEventListener is enough for handling the dispatched event.
Please find more details at the URL below.
Hope this helps.
So, do i understand this correctly:
to dispatch an event FROM component1 and hear it in component2, then one of the following must be true:
1-component 1 must 'know about' component2 (a reference to component1 must be passed to 2)
2-component2 must be a parent of component 1, and 'bubbles' must be true in my custom event, so that the event 'bubbles' up to its parent.
I guess that makes sense now that i really think about it. I guess reporting each component to see if it has listeners for every event would kill the system quickly, so instead of a generalized reporting system like that this paradigm is used.
So then, what is the best way to structure event dispatches and listeners for a large-scale application that will have lots of custom components all over the place? I don't want to be passing references to tons of components all over the place..... any suggestions/links for addressing this? thanks for the help!