Changing my Display...
OK! So, I've been developing my hangman game for quite some time now and this is basically how it works. Array of words, randomly generates one of the words, converts it into underscores and creates spaces between each underscore. What the user has to do, is enter a letter into the input text, push the guess_btn and then it will trace to see if the guessed letter is equal to the one that was randomly selected. If it is, it will convert it back into a letter and increase the rightcount. If it's not, then the movie clip will increase by one moving closer to the person dying. Sounds fairly simple. But the problem I have, is that even though it traces "True" on the correct letter, the "myDisplay" (which is the underscores) doesn't change the underscore to the guessed letter. Now I'm gonna paste a swath of code as how I think the game should function, and I'm going to highlight where the problem is in the code. Or where I think it is. All I want someone to say is "Oh, it's not changing from underscores because..." Please, please... Please, help me! I haven't got very long to make this game and I really need help! Thank you!
stop();
var words: Array = ["LONDON", "CYPRUS", "CHINA"];
//Creates array of the words to choose from
var number:Number;
var inProgress: String = new String;
var wordLength:Number;
var myDisplay: Array = new Array();
var displayOut: String = new String;
//Store number for correct guesses
var rightCount: Number = 0;
//Stores incorrect guesses
var used: String = new String;
//Holds the correct guess'd letter
var guess: String = new String;
//Holds the users correct guess
var guessLetter: String = new String;
//Holds the status of the guess
var correctGuess: Boolean = false;
number = (Math.floor(Math.random()* 3));
//Generating a random number
inProgress = words[number];
//Stores current word in the "inProgess" variable
wordLength = inProgress.length;
//Calculates legnth of the word
//For statement is used when you know how many times to loop
for (var i = 0; i <wordLength; i ++)
{
myDisplay = "_";
displayOut += " " + myDisplay;
}
//Creating the text in the text field for used letters
var answerText:TextField = new TextField();
var myFormat:TextFormat = new TextFormat();
myFormat.font = "Segoe UI Symbol";
myFormat.color = 0X00FF00;
myFormat.size = 23;
//The location of the text field
addChild(answerText);
this.answerText.x = 375;
this.answerText.y = 40;
this.answerText.width =250;
this.answerText.text = displayOut;
answerText.setTextFormat(myFormat);
this.guess_btn.addEventListener(MouseEvent.CLICK, playMe);
function playMe(Event:MouseEvent):void
{
//Switches all letters to capital
guessLetter = this.letterIn_txt.text.toUpperCase();
for(var i = 0; i< wordLength; i++)
{
if(inProgress.charAt(i) == guessLetter)
{
trace("true");
myDisplay=guessLetter;
correctGuess=true;
rightCount++;
}
}
}
if (correctGuess==false)
{
used+= this.letterIn_txt.text;
this.usedLetters_txt.text = used;
this.Comp.nextFrame();
}
else
correctGuess=false
displayOut = "";
for(var c=0; c < wordLength; c++)
{
displayOut += " " + myDisplay
}
this.answerText.text= displayOut;
this.answerText.setTextFormat(myFormat)
this.letterIn_txt.text = "";
if (rightCount == wordLength)
{
removeChild(answerText)
//Takes you to Scene 2
gotoAndStop(103)
}
