To put the gun to rotate related to mouse
ActionScript Code:
gun.rotation = Math.atan2(mouseY - gun.y, mouseX - gun.x) * 180 / Math.PI;
and to put the gun to point to the mouse
ActionScript Code:
gun.rotation = offsetDir + Math.atan2(mouseY - gun.y, mouseX - gun.x) * 180 / Math.PI;
where the offsetDir is the degrees value the gun is drawn to point from pointing right. Which means that if gun have been drawn to point up the offsetDir value is 90 or -270, left the offsetDir is 180 and if down the offsetDir is -90 or 270.
Edit: And to make gun to point to mouse every time the mouse is moving make mouse event event listener for mouse move and write the script above inside the handler function.