Not logged in

Event handling in Flextime is somewhat similar to jQuery/DOM event handling, but homogenized, with many of the quirks and corner-cases concealed.

Event handlers can be attached to a Flextime instance by using any of the convenience methods .draw(), .click(), .mousedown(), .mouseup(), .mousemove(), .keypress(), .keydown(), and .keyup(). More generally, event handlers can be attached with .on(eventname, handler) and removed with .off(eventname,handler) (if the handler argument is omitted, all events of the specified name are removed).

Multiple handlers can be attached for a given event type; handlers will be called in the order they are added. (See the multiple event handlers sample for a demonstration of how this can often simplify code involving multiple independent objects needing to respond to events.)

All event handlers have this bound to the active Flextime instance, and are passed an event object. The event object is simply the standard jQuery event object, augmented with a few additional convenience fields:

The draw event is called once per frame; as described above, it also has access to the current mouse (and possibly keyboard) state. In addition, if at least one handler is bound to the draw event, then the event object will have these additional timing-related fields:

Note that the event object is shared by all event handlers of a given type. Thus, any changes made to it will be seen by event handlers later in the chain.