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

Dynamic Text isn't displaying correctly

New Here ,
Mar 03, 2014 Mar 03, 2014

Hey, I'm following the steps to making a random number guessing game, but I can't seem to get my code to work. I am using dynamic and input texts to create an input and output for my game.

What the problem has been is that my guess button doesn't work. I'm not getting any error messages, but it won't output the text that changes based on my if/else statement. I'm not really sure whats wrong with it.

inputoutput.jpg

package  {

          import flash.display.MovieClip;

          import flash.events.MouseEvent;

 

          public class Main extends MovieClip {

 

                    var startMessage:String;

                    var mysteryNumber:uint;

                    var currentGuess:uint;

                    public function Main() {

                              init()

 

                              guessButton.addEventListener(MouseEvent.CLICK, onGuessButtonClick);

                    }

 

                    function init():void{

 

                              startMessage = "I am thinking of a number";

                              mysteryNumber = 50

                              currentGuess = uint(input.text);

 

                              output.text = startMessage;

                              input.text = "";

 

                              input.backgroundColor = 0xFFCCCCCC;

                              input.restrict = "0-9";

                              stage.focus = input;

                    }

 

                    function onGuessButtonClick(event:MouseEvent){

 

                              if(currentGuess > mysteryNumber){

                                        startMessage = "too high!";

                              }

                              else if (currentGuess < mysteryNumber){

                                        startMessage = "too low!";

                              }

                              else {

                                        startMessage =  "you win!";

                              }

                    }

          }

 

}

TOPICS
ActionScript
1.5K
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

correct answers 1 Correct answer

LEGEND , Mar 03, 2014 Mar 03, 2014

The first thing to always try is to embed the font in the textfield.  Another thing to check is that the textfield textcolor is not the same as the backbround color.

You should put traces in your onGuessButtonClick function so that you can confirm the conditionals are processing as expected.

Translate
LEGEND ,
Mar 03, 2014 Mar 03, 2014

The first thing to always try is to embed the font in the textfield.  Another thing to check is that the textfield textcolor is not the same as the backbround color.

You should put traces in your onGuessButtonClick function so that you can confirm the conditionals are processing as expected.

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 ,
Mar 03, 2014 Mar 03, 2014

It wasn't the background color. This time it was a mix of a couple issues. I moved the currentGuess variable into the onClick function, as well as changing all startMessages is the if/elses to just output.text = "" and it finally worked out. Thanks though, all the help and tips are really making my life easier!

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 ,
Mar 03, 2014 Mar 03, 2014
LATEST

You're welcome

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