So I’ve just finished this function for the guns in my first AS3 game. I have 8 of them and this makes them all rotate towards the mouse pointer. They just wouldn’t line up properly using evt.target.x or evt.currentTarget.x to parse the X/Y positions for the localToGlobal method but it works fine using this.x. Conversely using this instead of evt.target for the rotation wouldn’t work.
Can anyone explain to me the difference between using this, evt.target and evt.currentTarget?
var points:Point = new Point();
var newPoint:Point = new Point();
function rotateGuns(evt:Event):void
{
points.x = this.x;
points.y = this.y;
newPoint = evt.currentTarget.localToGlobal(points);
evt.currentTarget.rotation = getAngle(newPoint.x, newPoint.y, mouseX, mouseY);
}
function getAngle(x1:Number, y1:Number, x2:Number, y2:Number):Number
{
var radian:Number = Math.atan2(y2-y1, x2-x1);
return rad2deg(radian);
}