# EventDispatcher inner working

**URL:** <https://forum.kirupa.com/t/eventdispatcher-inner-working/318871>\
**Category:** flash\
**Created:** [February 2, 2011, 9:45am UTC](https://forum.kirupa.com/t/eventdispatcher-inner-working/318871 "2011-02-02T09:45:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Booya](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@Booya](https://forum.kirupa.com/u/Booya)\
**Post date:** [February 2, 2011, 9:45am UTC](https://forum.kirupa.com/t/eventdispatcher-inner-working/318871/1 "2011-02-02T09:45:51Z")

</div>

Hi - hopefully someone could help me out.

I want to simulate the Actionscript3.0 EventDispatcher in JavaScript.  
If you have seen a rebuild of the EventDispatcher I would be pleased to know about that 🙂

So if you dont know anything about JavaScript - thats not that important - maybe you know how you would rebuild the EventDispatcher in AS3, too  
It should not be impossible to translate that to JavaScript 🙂

I already got some features implemented (addEventListener with priority, dispatchEvent, removeEventListsner, hasEventListener)

Basically goes it like this:

addEventListener(type,listener,useCapture,priority,useWeakReference)

- adds listener to internal array via array[type][priority].push(listener)

dispatchEvent(event)

- iterates over array[event.type] and calls the assigned listeners in their priority/added order.

So i just added Event.stopImmediatePropagation()  
and realized that my architecture must be incorrect -  
I need Event to hold a public variable ‘cancelled’ to tell the dispatcher that he can stop looping through the listeners.  
How does the original EventDispatcher work without such a public var /  
Hoes does the dispatching works

Thanks for any suggestions
