Action Script 3 game error
I have been following a tutorial on Lynda.com for a game I am making for my daughter. It is a guessing game that I am using her spelling words for. When I make the game (or even try their excerise files) on my computer, only certain letters can be guessed instead of all. Also, it is supposed to show how many she has missed but doesn't and I can't figure out where the issue is for the life of me. Any idea?
Here is the A.S. code:
var loader:URLLoader;
var allWords:Array;
var thisWord:String;
var textContainer:MovieClip;
var textFields:Array;
var textStyle:TextFormat;
var underline:MovieClip;
var numCorrect:uint;
var totalLetters:uint;
var misses:uint;
var missesToLose:uint;
function initializeGame():void
{
loader = new URLLoader();
allWords = new Array();
textContainer = new MovieClip();
textFields = new Array();
textStyle = new TextFormat();
textStyle.font = "Courier New";
textStyle.size = 48;
textStyle.bold = true;
guesses_txt.text = "";
numCorrect = 0;
misses = 0;
missesToLose = 5;
misses_txt.text = "0";
missesToLose_txt.text = "/" + missesToLose;
textContainer.y = 100;
addChild(textContainer);
loader.load(new URLRequest("words.txt"));
loader.addEventListener(Event.COMPLETE, textLoaded);
guess_btn.addEventListener(MouseEvent.CLICK, guess);
}
function endGame(endMessage:String):void
{
var winLose:MovieClip = new WinLose();
addChild(winLose);
winLose.end_txt.text = endMessage;
winLose.addEventListener(MouseEvent.CLICK, playAgain);
}
function playAgain(event:MouseEvent):void
{
event.currentTarget.parent.removeChild(event.currentTarget);
removeChild(textContainer);
initializeGame();
}
function textLoaded(event:Event):void
{
var tempText:TextField;
var stringOfWords:String = event.target.data;
allWords = stringOfWords.split(",");
thisWord = allWords[Math.floor(Math.random() * allWords.length)];
totalLetters = thisWord.length;
for(var i:uint = 0; i < thisWord.length; i++)
{
tempText = new TextField();
tempText.defaultTextFormat = textStyle;
tempText.name = "textField" + i;
tempText.text = "";
tempText.width = 48;
tempText.x = i * tempText.width;
tempText.selectable = false;
textContainer.addChild(tempText);
textFields.push(tempText);
if(thisWord.charAt(i) != " ")
{
underline = new Underline();
underline.x = tempText.x + tempText.width /3;
underline.y = tempText.y + tempText.height/2 + 5;
textContainer.addChild(underline);
}
}
textContainer.x = stage.stageWidth /2 - textContainer.width/2;
}
function guess(event:MouseEvent):void
{
var wordLC:String = thisWord.toLowerCase();
if(guess_txt.text != "")
{
if(wordLC.indexOf(guess_txt.text) != -1)
{
for(var i:uint = 0; i < textFields.length; i++)
{
if(wordLC.charAt(i) == guess_txt.text)
{
textFields.text = thisWord.charAt(i);
numCorrect ++;
if(numCorrect >= totalLetters)
{
endGame("You Win!");
}
}
}
}
else if(guesses_txt.text == "")
{
guesses_txt.appendText(guess_txt.text);
misses ++;
}
else
{
guesses_txt.appendText("," + guess_txt.text);
misses ++;
}
}
misses_txt.text = String(misses);
if(misses >= missesToLose)
{
endGame("You Lose");
}
guess_txt.text = "";
}
initializeGame();
