The problem that I am experiencing here is that when the new game function is called, it is not removing all of the moviclips as it should. So, when you start clicking letters on the next game they do not always disapear as if there were 2 instances of them. I tried to put all of the movieclips inside of another movieclip so that I could remove that main MC. Any help would be great. Thanks.
//Array containing all of the answers
var gameAnswers:Array = ['Frosted Flakes','Cheerios','Honey Combs','Lucky Charms','Honey Bunches of Oats','Apple Jacks','Rice Krispies','Fruit Loops','Count Chocula','Boo Berry','Kangaroo Jack','Jack Be Nimble','Not on Your Life','Watch This','Look Before you Leap','Life is Good'];
var lettersArray:Array = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
//Attach the mcTheMan
//this.attachMovie('mcTheMan','mcTheMan',this.getNextHighestDepth(), {_x:175,_y:10});
var theAnswer:String = "";
var upperCaseAnswer:String = "";
var theGuess:String = "";
var spaceChecker:String = "";
var mcMaster:MovieClip = new MovieClip ;
var mcLineMaster:MovieClip = new MovieClip;
var myFormat:TextFormat = new TextFormat();
myFormat.size = 15;
myFormat.align = TextFormatAlign.LEFT;
var wrongCount:uint = 0;
btnNewGame.addEventListener(MouseEvent.CLICK, handleNewGame);
function handleNewGame(evt:MouseEvent):void
{
for (var h:uint=0; h < mcMaster.numChildren; h++)
{
this.mcMaster.removeChildAt(h);
}
this.removeChild(mcMaster);
wrongCount = 0;
btnNewGame.x = -120;
mcTheMan.gotoAndPlay(1);
trace(this.numChildren);
for (var b:uint= 0; b< this.numChildren; b++)
{
trace(this.getChildAt(b));
}
newGame();
}
function handleGuess(evt:MouseEvent):void
{
theGuess = evt.currentTarget.name;
trace(upperCaseAnswer);
for (var n:uint = 0; n < upperCaseAnswer.length; n++)
{
if (upperCaseAnswer.charAt(n) == theGuess)
{
trace("That is correct");
}
}
if (upperCaseAnswer.charAt(n) != theGuess)
{
mcTheMan.nextFrame();
wrongCount++;
if (wrongCount > 5)
{
btnNewGame.x = 425;
wrongCount = 0;
}
}
evt.currentTarget.parent.removeChild(evt.currentTarget);
}
function newGame()
{
for (var i:uint = 0; i < 26; i++)
{
var txtField:TextField = new TextField ;
var letterFrame:mcLetterHolder = new mcLetterHolder ;
letterFrame.name = lettersArray*;
txtField.defaultTextFormat = myFormat;
txtField.text = lettersArray*;
txtField.selectable = false;
txtField.x = 4;
txtField.y = 2;
letterFrame.buttonMode = true;
letterFrame.mouseChildren = false;
letterFrame.useHandCursor = true;
letterFrame.addChild(txtField);
letterFrame.addEventListener(MouseEvent.CLICK, handleGuess);
if (i < 13)
{
letterFrame.x = 25 + (40 * i);
letterFrame.y = 400;
}
else
{
letterFrame.x = (25 + (40 * i)) - 520;
letterFrame.y = 440;
}
mcMaster.addChild(letterFrame);
}
this.addChild(mcMaster);
// Get a random anser and convert to upper case for comparing to the guess.
theAnswer = gameAnswers[Math.floor(Math.random() * gameAnswers.length)];
upperCaseAnswer = theAnswer.toUpperCase();
// This for loop draws the empty lines relative to the answer.
for (var j:uint = 0; j < gameAnswers.length; j++)
{
spaceChecker = upperCaseAnswer.charAt(j);
if (spaceChecker != " ")
{
var blankLine:MovieClip = new MovieClip();
blankLine.graphics.lineStyle(2);
blankLine.graphics.moveTo(0,0);
blankLine.graphics.lineTo(15,0);
blankLine.x = 40 + (25*j);
blankLine.y = 380;
mcLineMaster.addChild(blankLine);
}
}
this.addChild(mcLineMaster);
}
newGame();
trace(this.numChildren);
for (var b:uint= 0; b< this.numChildren; b++)
{
trace(this.getChildAt(b));
}