I have a button (decrease), and when the button is pressed an arrow rotates left. I need the arrow to stop at a certain angle (approximately at 8 o’clock).
How can I get the angle of the arrow, and then stop it from rotating past this point (even if the user keeps pressing the button)?
Here’s my code:
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
stop();
var rotate = 0;
decrease.addEventListener(MouseEvent.MOUSE_DOWN, decreasePressed);
decrease.addEventListener(MouseEvent.MOUSE_UP, removeEnterFrame);
function decreasePressed(e:MouseEvent):void
{
rotate = -2;
addEnterFrame();
}
function addEnterFrame():void
{
this.addEventListener(Event.ENTER_FRAME, update);
}
function removeEnterFrame(e:MouseEvent):void
{
this.removeEventListener(Event.ENTER_FRAME, update);
}
function update(e:Event):void
{
arrow1.rotation += rotate;
}
Assuming your arrow has been created vertically with the arrow pointing upwards, the 8 o’clock position when rotating anti-clockwise (as you are doing) is at approximately -112 degrees. Therefore you need to add a check in your update method to ensure that the arrow’s rotation is not set to a value lower than -112: