(Canvas) Call one function from many eventListeners and include argument?
I cannot figure out how to pass an argument from addEventListener to a function. The code below works fine for dragging a single object and dropping on a target. But I have 3 objects that I would like to drag and drop, How can I alter the code below so that parameters for the dragged element and the target can be passed to the three functions (handleClick, handleMove, checkIt).
stage = this;
this.star.addEventListener("mousedown", handleClick.bind(this));
function handleClick(e) {
var global = stage.localToGlobal(stage.star.x, stage.star.y);
stage.star.offset = {
'x': global.x - e.stageX,
'y': global.y - e.stageY
};
console.log(global);
}
this.star.addEventListener("pressmove", handleMove.bind(this));
function handleMove(e) {
var local = stage.globalToLocal(e.stageX + stage.star.offset.x, e.stageY + stage.star.offset.y);
stage.star.x = local.x;
stage.star.y = local.y;
console.log(local);
}
this.star.addEventListener("pressup", checkIt.bind(this));
function checkIt() {
if(this.star.hitTest(this.star2.x - this.star.x,this.star2.y - this.star.y)){
this.field.text = "Yes";
stage.star.x = stage.star2.x;
stage.star.y = stage.star2.y;
} else {
this.field.text = "no";
stage.star.x = 100;
stage.star.y = 100;
}
}
