Actionscript: Input text filed won't accept numerical input
Apr 15, 2011 at 5:43am UTC
Using AS3 to create a basic number guessing game but for some reason the input text field won't accept text input. I can't figure out which piece of code is causing the problem and it's driving me nuts considering it's from a tutorial. I've been over each line again and again and I can't figure it out. Any help is appreciated:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
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();
}
function init():void
{
startMessage = "I am thinking of a number between 1 and 100" ;
mysteryNumber = 50;
output.text = startMessage;
input.text = "" ;
input.backgroundColor = 0xFFCCCCCC;
input.restrict = "0-9" ;
stage.focus = input;
guessButton.addEventListener(MouseE… onGuessButtonClick);
}
function onGuessButtonClick(event:MouseEvent):voi…
{
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!" ;
}
}
}
}
Apr 15, 2011 at 3:30pm UTC
bump
Anyone who can help at all?
Topic archived. No new replies allowed.