Skip to main content
Participant
June 4, 2014
Answered

It appear "That's too low" when it should appear me "I am thinking of a number between 0 and 99"

  • June 4, 2014
  • 1 reply
  • 215 views

This is mi Code pls HELP

It would be really apracate it the Help (sorry for the bad english)

package

{

  import flash.display.Loader;

  import flash.display.Sprite;

  import flash.events.KeyboardEvent;

  import flash.events.MouseEvent;

  import flash.net.URLRequest;

  import flash.text.*;

  import flash.ui.Keyboard;

  [SWF(width="550", height="400", backgroundColor="#FFFFFF", frameRate="60")]

  public class NumberGuessingGame extends Sprite

  {

  //In/Output vareables

  public var format:TextFormat = new TextFormat();

  public var output:TextField = new TextField();

  public var input:TextField = new TextField();

  //Game Vareables

  public var startMessage:String;

  public var mysteryNumber:uint;

  public var currentGuess:uint;

  public function NumberGuessingGame()

  {

  setupTextField();

  startGame();

  playGame();

  }

  public function setupTextField()

  {

  //Set the text format objects

  format.font = "Helventica";

  format.size = 32;

  format.color = 0xFF0000;

  format.align = TextFormatAlign.LEFT;

  //Configure the output text field

  output.defaultTextFormat = format ;

  output.width = 400;

  output.height = 80;

  output.border = true;

  output.wordWrap = true;

  output.text = "This is the output text field";

  //Display and position the output text field

  stage.addChild(output)

  output.x = 70;

  output.y = 65;

  //Configure the input text field

  format.size = 60;

  input.defaultTextFormat = format;

  input.width = 80;

  input.height = 60;

  input.border = true;

  input.background = true;

  input.backgroundColor = 0xCCCCCC;

  input.type = "input";

  input.text = "";

  input.maxChars = 2;

  input.restrict = "0-9";

  input.displayAsPassword = false;

  input.selectable = true;

  //Display the position of the Input text field

  stage.addChild(input);

  input.x = 70;

  input.y = 150;

  stage.focus = input;

  }

  public function playGame():void

  {

  currentGuess = uint(input.text);

  if(currentGuess > mysteryNumber)

  {

  output.text = "That's too high.";

  }

  else if (currentGuess < mysteryNumber)

  {

  output.text = "That's too low.";

  }

  else

  {

  output.text = "You got it!";

  }

  }

  public function keyPressHandler(Event:KeyboardEvent):void

  {

  if(Event.keyCode == Keyboard.ENTER){

  playGame();

  }

  }

  public function startGame():void

  {

  //Initialize variables

  startMessage = "I am thinking of a number between 0 and 99";

  mysteryNumber = 50;

  //Initialize text fields

  output.text = startMessage;

  input.text = "";

  //add an event listener for key presses

  stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressHandler);

  }

  }

}

This topic has been closed for replies.
Correct answer Ned Murphy

Try getting rid of the playGame() function call in the NumberGuessingGame function.  If you call it right away the value of the guess will be the default value of a uint (0) which is less than 50.

public function NumberGuessingGame()

{

  setupTextField();

  startGame();

  playGame();

}

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
June 4, 2014

Try getting rid of the playGame() function call in the NumberGuessingGame function.  If you call it right away the value of the guess will be the default value of a uint (0) which is less than 50.

public function NumberGuessingGame()

{

  setupTextField();

  startGame();

  playGame();

}

MirormiAuthor
Participant
June 4, 2014

thanks bro!

Ned Murphy
Legend
June 4, 2014

You're welcome