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