I'm quite new to JS's prototypying but not to oop in general. New to easeljs, however. Having said that, i've been trying to get an object variable triggered by a click event, and i REALLY can't seem to find a decent way of doing it.
Trying to build a clickable 2D "board", here is my test code:
(function() { //"Class"
Brick = function() {
this.initialize();
};
var p = Brick.prototype = new createjs.Container();
p.Container_initialize = p.initialize;
p.initialize = function() {
this.Container_initialize();
};
p.create = function(row, column) {
this.row = row;
this.column = column;
//Shape
this.square = new createjs.Shape();
this.square.graphics.beginFill("green").drawRect(0, 0, brickSize, brickSize);
this.x = (brickSize * column) + (Game.padding * column); // Add some padding
this.y = (brickSize * row) + (Game.padding * row); // Add some padding
this.addChild(this.square);
this.addEventListener("click", function(event) { console.log(this.row)})
};
})();
After this I just create a few Bricks cycling through a multidimensional array cycle, and add them to the stage. The board shows perfectly, however, i keep getting "undefined" while cliking. console.log(event.currentTarget.row) works though, but not sure it's the way to go.
Thanks!