Custom Event Dispatcher with object data, Actionscript 3

I have always used custom events in Actionscript 3 to completing my projects … but lately i had to send out a movieclip along my custom event … i did not yet know how i had to achieve this so i began testing and playing around …

For anbody who will need to send out a object (movieclip, sprite , …. , or any other custom build class) along with the event that is dispatched … this is what you will need to do …

What we need :

1. A custom class of that particular custom event (holding the data object, which can hold any datatype what so ever indicated by the “*” , and the event type , in this case MY_CUSTOM_EVENT)

Custom Events Class

Custom Events Class

2. A custom event dispatcher which dispatches the event with the data object

Dispatching The Custom Event

Dispatching the CustomEvent

3. An eventlistener to listen for the custom event when dispatched

Event Listener

Event Listener : listening for the CustomEvent

Do not forget importing the reference to your CustomEvent class and other related classes needed …

Event driven programming has made my projects code more structured, easy to maintain and optimalized … I really advise starting programmers to use this method …

1 comment so far

  1. lode on

    this is indeed a great way to do it, this way you keep your code clean and organised, thank you!


Leave a reply