Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Action Script 3 game error

New Here ,
Jun 29, 2013 Jun 29, 2013

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();

TOPICS
ActionScript
716
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 29, 2013 Jun 29, 2013

What is the problem? What errors do you get?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 01, 2013 Jul 01, 2013

It doesn't show any errors but has some if you know what I mean.  For example, you can guess the letter a but not the letter s.  Also, it doesn't show the misses like it is supposed to and I am not sure why.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 02, 2013 Jul 02, 2013
LATEST

It is time consuming to reverse engineer code. So, you will be better off getting help if you devote a threads one per issue.

Also, in the code there are two classes Underline and WinLose that you don't show.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines