Search code examples
eventsflashdispatchevent

How flash dispatchEvent really works?


It is said in the docs, that EventDispatcher's dispatchEvent "...dispatches an event into the event flow". The phrase is nice-looking and doesn't really explain anything.

Say, we have two listeners waiting for an event "A" on object "a", so what behaviour do we have to expect on calling:

a.dispatchEvent("A")?

Would both listeners be called immediately, before return from distpatchEvent? Or they will be queued in some internal flash player queue and will be processed by entering the next frame? Can we rely on some defined behaviour of flash player here or the behaviour is undefined? How one should read "dispatches an event to event flow"? The question is important since in practice it affects the control flow of the code.


Solution

  • Just use Signals instead :P

    https://github.com/robertpenner/as3-signals/wiki

    No but really, they're very easy to use and understand, a great addition to the AS3 toolbox.

    You can also learn a lot about how native AS3 events work by reading Rob Penner's critiques (scroll down to bottom of wiki page)