From 60b147ea72af160faf826b03f9386edd7c8f69ca Mon Sep 17 00:00:00 2001 From: Martin Kelm Date: Thu, 8 Aug 2013 11:04:40 +0200 Subject: [PATCH] added PIXI.EventTarget in Element for interactions --- lib/MCT/Display/Object.js | 10 +++++----- lib/MCT/Element.js | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/MCT/Display/Object.js b/lib/MCT/Display/Object.js index 3ec94b7..953b542 100644 --- a/lib/MCT/Display/Object.js +++ b/lib/MCT/Display/Object.js @@ -221,16 +221,16 @@ MCT.DisplayObject.prototype.createButton = function(options) { } MCT.DisplayObject.prototype.setInteraction = function(sprite, options) { - if (typeof options.action != "undefined" && typeof options.type != "undefined") { + if (options.element instanceof MCT.Element && typeof options.type != "undefined") { sprite.setInteractive(true); + var callback = function() { + options.element.dispatchEvent( { type: options.type, content: options.data } ); + }; switch (options.type) { case "click": - sprite.click = options.action; + sprite.click = callback; break; } - if (typeof options.data != "undefined") { - sprite.mctInteractionData = options.data; - } } } diff --git a/lib/MCT/Element.js b/lib/MCT/Element.js index 69e65e7..86a64b6 100644 --- a/lib/MCT/Element.js +++ b/lib/MCT/Element.js @@ -26,6 +26,9 @@ MCT.Element = function(name) { this.name = name || "random" + Math.floor(Math.random() * 1000); this.grid = null; this.layout = null; + // use pixi event target to handle display object interaction events + // see -> https://github.com/MKelm/pixi.js/blob/dev/src/pixi/utils/EventTarget.js + PIXI.EventTarget.call(this); } MCT.Element.prototype.constructor = MCT.Element; \ No newline at end of file