Not to long ago I was inspired by Jason Cook's article Centralized Event Management in ActionScript 2.0.  So inspired in fact, that I didn’t read the whole thing.  What? Yeah, that doesn’t sound very inspired does it.  Well it is — in a way.  I was actually so intrigued that I wanted to do more than just learn by reading.  I wanted to create something.  Learn by doing. Learn the ins and outs, the nitty gritty. So I rolled my own.  Why am I telling you all this? Yeah, time to get to the point.  Not long after I made my own EventManager, I had to update it to AS 3  (mostly to bore you with these long anecdotes!).

And so now that I am passing my version of this EventManager along, I wanted to give credit where it’s due.  And although the features of my  EventManager are different,  Jason Cook's EventCenter was the inspiration to everything that follows in this tutorial.

As a side note, there are some who might debate the merits of such a system of events and consider it bad OOP.  While I respectfully disagree, please see this forum post to delve into that discussion if you wish.

Okay, phew -- we got that cheesy intro friendly banter paragraph out of the way, so let’s dig into the nitty gritty!


Why?

What do we hope to accomplish:

  • Provide a central place that objects and classes can connect to as listeners and jam out while listening to that great new wave event music.
  • Loosen the coupling in our applications and websites by allowing objects to remain unaware of each other.  Loosen our ties too! (who wears ties?)
  • Enable debugging of the sequence our events are firing.  (what did that event just say to me?)
  • Provide new functionality to remove all listeners. (Or tell all those  long-winded-jabber-mouth broadcasters they need to hush up!)
  • Add a new longevity feature to listeners and dispatchers. (Some need life support!)

Who?

Not for Everyone.  This tutorial is for the following people and/or robots:

  • Intermediate ActionScript 3 developers.
  • Basic understanding of OOP and class inheritance.
  • Those with a working knowledge of events.
  • Banana enthusiasts.

What?

What are some of the things this system could be used for?

  • Small “postcard” or portfolio websites.
  • Flash games
  • Interactive banner ads and Rich Media.

Not?

I don’t like to admit this in public but it’s true that there is some stuff centralized event management isn’t cut out for:

  • Complex Applications
  • Projects with multiple ActionScript developers
  • Anything where the complexity is enough to justify a framework
  • NASA rovers