title: making an object rotate according to the cursor position
body: <p>I am trying to make a game in which a cannons barrel is lifted or lowerd according to the cursor's position.</p>
  
  <p>Here is the code I inserted inside the Barrel mc:</p>
  
  <pre><code>import flash.events.Event;
  var hypotenuse,ratio,angleRad,angleDeg:Number;
  stage.addEventListener(Event.ENTER_FRAME,spin);
  
  function spin (e:Event):void{
      trace(mouseX+ " " + mouseY);
  hypotenuse = Math.sqrt((mouseX)*(mouseX)+(mouseY)*(mouseY));
  ratio = (Math.abs(mouseX))/hypotenuse;
  angleRad = Math.asin(ratio);
  angleDeg = angleRad*180/Math.PI;
  if(mouseX &gt;= 0 &amp;&amp; mouseY &lt;= 0 ){
      this.rotation = angleDeg;
  }
  if(mouseX &gt;= 0 &amp;&amp; mouseY &gt; 0){
      this.rotation = (90-angleDeg)*2;
  }
  if(mouseX &lt; 0 &amp;&amp; mouseY &gt; 0){
      this.rotation = angleDeg + 180;
  }
  if( mouseX &lt; 0 &amp;&amp; mouseY &lt;= 0){
      this.rotation = (90-angleDeg)*2;
  }
  }
  </code></pre>
  
  <p>For some reason the barrel is just jerking around and not even in the direction where the mouse is at.. =/ I would love some advice or maybe a different coding suggestions
  this is a problem I'v been trying to solve for a while now and i dont know what i am doing wrong.</p>