|
Were talking to the enter_btn inside the interface_mc movieclip, so we need to set the scope:
//Build a callback for the button inside of interface_mc.
interface_mc.enter_btn.onRelease = function(){
//Assume the player guessed wrong
var wrong = true;
//Loop through all the letters in the lettersNeeded array (made from selectedWord's letters) and change wrong to false as soon as we find a match.
for(counter=0;
counter < selectedWord.length;
counter++) {
//Check if the input is in lettersNeeded, but also not in lettersGuessed.
if (lettersNeeded[counter]
== interface_mc.input
&& lettersGuessed[counter]
!= interface_mc.input){
//test...
trace("guessed a letter correctly");
//guess matches a letter in the word, so it's not wrong.
wrong = false;
//decrement the number of letters left to go
lettersLeftToGo--;
//test...
trace("lettersLeftToGo is: "
+ lettersLeftToGo);
//put the correct answer in the lettersGuessed array at it's corresponding position
lettersGuessed[counter]
= interface_mc.input;
//test...
trace("lettersGuessed is: "
+ lettersGuessed.toString());
}
//Set the display text to what's in the lettersGuessed array.
interface_mc.display
= lettersGuessed.join("");
//end of for loop
}
//reset the input field;
interface_mc.input = "";
//If the guess was no good, step to the next frame.
if(wrong){
//Test...
trace("guessed incorrectly");
hangman_mc.nextFrame();
if (hangman_mc._currentFrame == 10) {
// GAME OVER!
interface_mc._visible = false;
playGame_btn._visible = true;
}
}
//If all the letters have been guessed correctly, go to the Win label of the hangman_mc.
if(lettersLeftToGo == 0) {
//GAME WON!
hangman_mc.gotoAndStop("win");
interface_mc._visible=false;
playGame_mc._visible = true;
}
}
|