Skip to content
parisminton edited this page Jan 15, 2012 · 4 revisions

EventDispatcher is an object that manages logic and state for all events on the stage. As of this writing, you only need one instance per stage.

Create an instance by invoking its constructor with the new keyword. (This may change.) No arguments necessary:

var e = new EventDispatcher();

An EventDispatcher instance loops through all the Characters in the timeline, identifying those with event handlers by testing for their userEvents property -- an array of strings naming the event. Every Character with a userEvents property should have a corresponding handler:

var play = new Button("play", false);
play.userEvents = ["click", "mousemove"];
play.clickHandler = function () {
  this.animator.animate();
}
play.mousemoveHandler = function () {
  this.foo();
  ...
}

For each event, the EventDispatcher instance attaches the appropriate handler to the Canvas element. It also stores an object containing events mapped to their handlers in its dispatchers property: EventDispatcher.dispatchers = { click : function () { handleclick; }, mousedown : function () { handlemousedown; } ... }

Clone this wiki locally