Hello!
Im still a tad sketchy on how event listeners/dispatchers are meant to be used and how they work exactly. Ive scoured the internet but like usual i get a list of 3 common sites that dont really directly answer any questions ive got, so if any of you guys can answer i would be greatly appreciative!
-
When an event dispatcher/listener is created is it only able to dispatch and listen to events within its current scope, or are events global automatically and heard by any event listener? i.e Class A dispatches a function that Class C should listen for.
-
When you enter your function in the eventlistener, should you always do the full path to the function or just a short path? i.e Class A wants to listen for a COMPLETE event, then trigger the method doStuff(), so would it be:
addEventListener(Event.COMPLETE, this.doStuff);
addEventListener(Event.COMPLETE, doStuff);
Funny thing is the above doesnt acctually work within a class, however if you are using a loader and use the .contentLoaderInfo.addEventListener… it does, can anyone explain why this works and the normal declaration doesnt?
-
If there are 3 listeners all listening out for the same event in the same scope however they all trigger different functions, would 1 event dispatch trigger them all? Is there a way that you can define which listener you want to target…?
-
This ones kinda related to question 1, but if you were to make a global event handler and you made it listen for events then dispatch them to specific objects methods, how would you link to the specific objects function as chances are it would be out of scope, would you pass it a function pointer?
There may be more questions based off the answers here, but these are the simplest questions that i can think of that would greatly benefit me if i knew the answers!