Deathwalker666
04-23-2011, 08:33 PM
Hi guys.
Really tearing my hair out with this problem. I've managed to get all the way with this Flash Hangman minigame, then noticed this problem. Everything works fine, but if there's a word with more than 1 of the same letter in it, only the first one of that letter works. For example, if the hangman word is baboon, and the player pressed O, only ___O___, rather than _____OO__. Here is the code I'm using to check the letters:
//Letter has been selected
function selectLetter(event:MouseEvent) {
//Hide the selected letter
event.target.mouseEnabled=false;
event.target.parent.visible=false;
//Guessed word is it's letter
guessLetter=event.target.parent.character.text;
//If the letter is correct
if (hangWord.indexOf(guessLetter)>-1) {
//Access the selected letter, and make it visible
wordHolder.getChildByName("hangmanLetter_"+guessLetter).visible=true;
lettersCorrect+=1;
//If all the letters are correct
if (lettersCorrect==hangWord.length) {
trace("COMPLETE");
}
} else {
lives-=1;
hangman.nextFrame();
wrongX+=20;
//Put an incorrect letter
var theWrong:wrongLetter = new wrongLetter();
theWrong.letter.text=guessLetter.toUpperCase();
theWrong.x=wrongX;
incorrectHolder.addChild(theWrong);
//If all lives are gone
if (lives==0) {
trace("GAME OVER");
}
}
}
Basically, I need to check if the word contains that letter, and if it does find one, carry on checking through the rest of the word.
I know it's not much to go on, but hopefully someone can help :)
Thanks guys
Really tearing my hair out with this problem. I've managed to get all the way with this Flash Hangman minigame, then noticed this problem. Everything works fine, but if there's a word with more than 1 of the same letter in it, only the first one of that letter works. For example, if the hangman word is baboon, and the player pressed O, only ___O___, rather than _____OO__. Here is the code I'm using to check the letters:
//Letter has been selected
function selectLetter(event:MouseEvent) {
//Hide the selected letter
event.target.mouseEnabled=false;
event.target.parent.visible=false;
//Guessed word is it's letter
guessLetter=event.target.parent.character.text;
//If the letter is correct
if (hangWord.indexOf(guessLetter)>-1) {
//Access the selected letter, and make it visible
wordHolder.getChildByName("hangmanLetter_"+guessLetter).visible=true;
lettersCorrect+=1;
//If all the letters are correct
if (lettersCorrect==hangWord.length) {
trace("COMPLETE");
}
} else {
lives-=1;
hangman.nextFrame();
wrongX+=20;
//Put an incorrect letter
var theWrong:wrongLetter = new wrongLetter();
theWrong.letter.text=guessLetter.toUpperCase();
theWrong.x=wrongX;
incorrectHolder.addChild(theWrong);
//If all lives are gone
if (lives==0) {
trace("GAME OVER");
}
}
}
Basically, I need to check if the word contains that letter, and if it does find one, carry on checking through the rest of the word.
I know it's not much to go on, but hopefully someone can help :)
Thanks guys