title: Drag object around a circle on mouse over - Adobe Animate/Create.js/Easel.js
body: <p>Using Adobe Animate HTML5 Canvas which employs Create.js/Easel.js.</p>
  <p>I have the following code which drags an object around a circle.</p>
  <p>Works Ok, but the object should only be moveable when the cursor is over the object; object being <code>streakRotatorKnob</code>.</p>
  <pre><code>var knob_X = 454;
  var knob_Y = 175;
  var radius = 80;
  
  root.streakRotatorKnob.addEventListener(&quot;pressmove&quot;,moveF.bind(this));
  
  function moveF(e){ 
  var rads = Math.atan2(stage.mouseY-knob_Y,stage.mouseX-knob_X);
  e.currentTarget.x = knob_X + radius * Math.cos(rads);
  e.currentTarget.y = knob_Y + radius * Math.sin(rads);
  stage.update();
  }
  </code></pre>
  <p>I have tried the following but it's not working at all with the <code>if statement</code>:</p>
  <pre><code>var knob_X = 454;
  var knob_Y = 175;
  var radius = 80;
  
  root.streakRotatorKnob.addEventListener(&quot;pressmove&quot;,moveF.bind(this));
  
  function moveF(e){
      if(stage.mouseY == root.streakRotatorKnob.y &amp;&amp; stage.mouseX == root.streakRotatorKnob.x){
  var rads = Math.atan2(stage.mouseY-knob_Y,stage.mouseX-knob_X);
  e.currentTarget.x = knob_X + radius * Math.cos(rads);
  e.currentTarget.y = knob_Y + radius * Math.sin(rads);
  stage.update();
      }
  }
  </code></pre>
  <p><strong>UPDATE</strong></p>
  <p>Based on Muhammed Maruf's answer below (the Adobe Animate version), the following works better by removing the line:</p>
  <pre><code>root.c.addEventListener(&quot;rollout&quot;, rollout);
  </code></pre>
  <p>So we just have:</p>
  <pre><code>stage.enableMouseOver();
  var knob_X = 454;
  var knob_Y = 169;
  var radius = 90;
  var root = this;
  
  
  root.c.addEventListener(&quot;rollover&quot;, rollover);
  //root.c.addEventListener(&quot;rollout&quot;, rollout);
  
  function rollover(e)
  {
      console.log(&quot;rollover&quot;)
      root.c.addEventListener(&quot;pressmove&quot;, moveF);
  }
  function rollout(e)
  {
      console.log(&quot;rollout&quot;)
      root.c.removeEventListener(&quot;pressmove&quot;, moveF);
  }
  function moveF(e)
  {
      var rads = Math.atan2(stage.mouseY - knob_Y, stage.mouseX - knob_X);
      e.currentTarget.x = knob_X + radius * Math.cos(rads);
      e.currentTarget.y = knob_Y + radius * Math.sin(rads);
      stage.update();
  }
  </code></pre>