In this game I made some cubes fall and you have to avoid them. When you've avoided one, it keeps falling and hits the ground (scoreDetector), so everytime it hits the ground, I get 1 point. The problem is that the animatione of the cube keeps looping (that's what I want) but by doing so the score counter removes the point and keeps adding and removing it everytime the animation of the cube starts.
Code:
var time:int;
var timer:Timer = new Timer(1000,0);
var score:int = 0;
score = 0;
scoreCounter.text = "Score: " + score;
timer.addEventListener(TimerEvent.TIMER, cubeFall);
timer.start();
function cubeFall(t:TimerEvent) {
time++;
if (time == 3) {
cube_1.play();
} else if (time == 10) {
cube_2.play();
}
// Add Score
else if (cube_1.hitTestObject(scoreDetector)) {
score++;
scoreCounter.text = "Score: " + score;
}
}