Copy link to clipboard
Copied
I'm a beginner with AS3, I'm trying to create a program that when I click on a coloured ball it rotates 90° and when clicked again it goes back to it's starting position ie. -90°.
The code that I have here works already. I was just wondering does anyone know what code I would put in to get it to return to the starting position.
import flash.events.MouseEvent;
myColouredBall.addEventListener(MouseEvent.MOUSE_DOWN, doClick);
function doClick (e:MouseEvent):void
{
myColouredBall.rotation = 90;
}
Hope someone can help! Thanks.
function doClick(e:MouseEvent):void {
if (myColouredBall.rotation > 0) {
myColouredBall.rotation = 0;
} else {
myColouredBall.rotation = 90;
}
}
Copy link to clipboard
Copied
function doClick(e:MouseEvent):void {
if (myColouredBall.rotation > 0) {
myColouredBall.rotation = 0;
} else {
myColouredBall.rotation = 90;
}
}
Copy link to clipboard
Copied
Thank you so much! Works like a charm
Copy link to clipboard
Copied
You're welcome
Copy link to clipboard
Copied
import flash.events.MouseEvent;
var hasMoved:Boolean = false;
myColouredBall.addEventListener(MouseEvent.MOUSE_DOWN, doClick);
function doClick (e:MouseEvent):void {
if(!hasMoved) {
myColouredBall.rotation = 90;
} else {
myColouredBall.rotation = 0;
}
hasMoved = !hasMoved;
}