(Canvas) Call one function from many eventListeners and include argument?


i cannot figure out how pass argument addeventlistener function.  code below works fine dragging single object and  dropping on a  target.   have 3 objects drag , drop, how can alter code below parameters dragged element , target can passed 3 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;

  }

}

the answer right there in event handler-- e event object.

easeljs v0.8.2 api documentation : mouseevent

 

alternatively, in drag start handler can use value of this store global pointer clicked object (assuming used on or bind assign event handler).

 

also don't put property names in object literals in quotes. i'm surprised works.



More discussions in Adobe Animate CC - General


adobe

Comments

Popular posts from this blog

Reader DC

Adobe InDesign CC 2017 has stopped working

Acrobat DC体験版の試用期間が7日間となってしまう。14日間との認識です が?