Skip to content
flashlizi edited this page May 7, 2012 · 13 revisions

Handle Events

  • Use Q.EventManager to register events for stage.
var em = new Q.EventManager();
var events = Q.supportTouch ? ["touchstart", "touchmove", "touchend"] : ["mousedown", "mousemove", "mouseup"];
em.registerStage(stage, events);
  • Write event handlers for the specific display object.
obj.addEventListener("touchend", function(e)
{
	//do something
});

In the event handler, you can obtain e.eventX, e.eventY, e.eventTarget, e.lastEventTarget for your specific use.

  • Remove event listener.
//remove a specific handler by event type.
obj.removeEventListener("touchend", touchendHandler);

//remove all handlers by event type.
obj.removeEventListener("touchend");
  • Unregister events from stage.
em.unregisterStage(stage, events);
  • Aliases for some methods.
obj.on = obj.addEventListener
obj.un = obj.removeEventListener
obj.fire = obj.dispatchEvent
Clone this wiki locally