AS3: Main
This tutorial will produce something like this in AS3 code.
Create a new AS3 document. Draw an arrow pointing left, and make it a movieclip. Give it an instance name of "arrow". Then put this code onto the main frame of the timeline:
import DisplayObject.*;
this.addEventListener(Event.ENTER_FRAME, OEF);
function OEF(Event){
xdif = mouseX-arrow.x;
ydif = mouseY-arrow.y;
arrow.rotation = Math.atan2(ydif, xdif)/(Math.PI/180);
}
What does this mean? Lets break it down:
import DisplayObject.*; - This code imports the mouseX and mouseY values.
this.addEventListener(Event.ENTER_FRAME,OEF); - This creates a new eventListener, that runns the function "OEF", and makes it run every frame. This is the AS2 equivalent of onEnterFrame = function().
function OEF(Event){ - This defines the OEF function.
xdif = mouseX-arrow.x;
ydif = mouseY-arrow.y; - These codes work out the x and y differences between the arrow and the mouse.
arrow.rotation = Math.atan2(ydif, xdif)/(Math.PI/180); - This uses trigonometry to work out the angle using the x and y differences.
This is my first tutorial, and its one of the first AS3 ones! Lucky I nabbed an easy topic before they all went...