저는 JS의 프로토 타이핑에는 새로운 것이지만 일반적으로는 아닙니다. 그러나 easeljs에 새로운. 그런데, 나는 click 이벤트에 의해 트리거 된 객체 변수를 얻으려고 노력해 왔으며, 정말로 괜찮은 방법을 찾을 수없는 것처럼 보입니다. 이 후easeljs 클릭 이벤트로 프로토 타입 변수 읽기
(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)})
};
})();
난 그냥 다차원 배열주기를 순환 몇 벽돌을 만들고, 무대에 추가 : 클릭 할 수있는 2D "보드"를 구축을 위해 노력
, 여기 내 테스트 코드입니다. 보드가 완벽하게 보이지만, 나는 cliking 동안 계속 "정의되지 않은"상태를 유지합니다. console.log (event.currentTarget.row)는 작동하지만 확실한 방법은 아닙니다.
감사합니다.
var p = Brick.prototype = Object.create(createjs.Container.prototype);
이벤트 핸들러가 this
에 대한 잘못된 값이 있습니다