Is there s simple way to code a user control analog clock. I am just looking for the ability to drag the big (minute) hand around the clock.
This is as far as I’ve gotten:
class Main extends Sprite
{
public var clock:Bitmap = new Bitmap(Assets.getBitmapData("img/clock.png"));
public var bigHandBMP:Bitmap = new Bitmap(Assets.getBitmapData("img/handBig.png"));
public var bigHand:MovieClip = new MovieClip();
public var xPos:Float = 0;
public var yPos:Float = 0;
public var oldRotation:Float = 0;
public var pressing:Bool = false;
public function new()
{
super();
addChild(clock);
bigHandBMP.x = -30;
bigHandBMP.y = -292;
bigHand.addChild(bigHandBMP);
bigHand.x = 300;
bigHand.y = 300;
addChild(bigHand);
stage.addEventListener(MouseEvent.MOUSE_DOWN, ClickHandler);
stage.addEventListener(MouseEvent.MOUSE_UP, ReleaseHandler);
stage.addEventListener(MouseEvent.MOUSE_MOVE, MovingHandler);
}
public function MovingHandler(m:MouseEvent)
{
if (pressing == true) {
if (bigHand.rotation >= -90 && bigHand.rotation <= 90) {
bigHand.rotation = oldRotation + stage.mouseX - xPos;
}
}
}
public function ClickHandler(m:MouseEvent)
{
if (bigHand.hitTestPoint(mouseX, mouseY, true) && pressing == false) {
pressing = true;
xPos = stage.mouseX;
oldRotation = bigHand.rotation;
}
}
public function ReleaseHandler(m:MouseEvent)
{
pressing = false;
}