Set a maximum for a variable for success + Kill a function
Hi there,
I have a project in which
1. I have a custom cursor
2. An object ( moving target) moving randomly.
3. On clicking the object a variable is increased and shown in a dynamic text field.
4. I have a button that stops and plays the movie + also a button that resets the value of the hits variable.
5. A hidden success message. Just an object with a text that would appear once the user hits 10 times the object and increases the variable to 10.
In a way, we can think of it as a game in which someone is shooting on a target.
I have two issues here.
A. I cannot stop the random movement of the target. Must be really a simple thing. The object is set to move with the function
function moveIt(it) {
TweenLite.to(it, (Math.random() * 2) + 0.5, {x:Math.random() * 400, y:Math.random() * 400, onComplete:moveIt, onCompleteParams:[it]});
}
which is started by the Play Pause button.
Here is the code hooked to the Play Pause button
isPlaying is a Boolean to decide if the movie will play or pause
I assign the button labels of the toggle Play Pause button to their instance names - inst_BtnLabel
this.inst_PlayPause.addEventListener("click", fl_MouseClickHandler.bind(this));
function fl_MouseClickHandler() {
if(isPlaying == false){
this.play;
this.inst_PlayPause.inst_BtnLabel.text = "stop";
this.inst_PlayPause.inst_BtnLabel.mouseEnabled = false;
moveIt(this.inst_ButtonIncrease);
isPlaying = true;
this.debug_Boolean.text = isPlaying;
}
else
{
this.inst_PlayPause.inst_BtnLabel.text = "play";
this.inst_PlayPause.inst_BtnLabel.mouseEnabled = false;
this.stop;
isPlaying = false;
this.debug_Boolean.text = isPlaying;
moveIt(this.inst_ButtonIncrease); //I know that here I need to insert the code that stops the function
}
}
How can I stop the random movement function?
B. I would like to have a maximum/end value of the variable (countHits) which would stop the movie and show a success message.
I have thought of the success message as a movie that is initially hidden.
Once the maximum value (lets say 10) is reached, the hidden movie will start playing and the other movies will stop.
Thanks in advance for the ideas.
B
