Input Text problem, ActionScript 3.0


I'm making a simple password for a website, where the password is stored as a string on a timeline script.

I'm using nested conditionals (which may not be very elegant but should work) to first react when the enter key is pressed, and then look at the contents of the input text.

If the input text isn't the same as the password, then it goes to an error page, otherwise it goes to on to let you in on the website.

However, the code below is not robust enough, because if I press only the Enter key, the input text is not trapped by the conditionals. I've been trying to figure this out for ages now, and I can't.

Also, another question. I would like to be able to clear the input text area, when an error is detected. How can I do that?
var nameText:String = "hello"
stage.addEventListener(KeyboardEvent.KEY_DOWN, hitKey);
function hitKey(evt:KeyboardEvent):void 
	if (evt.keyCode == Keyboard.ENTER)
		if (inputText.text != nameText)
		trace("error: "+inputText.text);
		gotoAndStop(2);//displays an error message
		trace("accepted: "+inputText.text);
		gotoAndStop(3);//starts movie
trace ("Outside conditionalas: inputText.text = "+inputText.text)

Open in new window

LVL 11
Who is Participating?
FlyingFlashConnect With a Mentor Commented:
Even though this will work outside of Flash if you change the order of your conditionals so that access is granted only when the "if" condition passes

i.e.  if (inputText.text == nameText) ... // "accepted"

and put the "error" condition in the "else" statement then it will work in Flash as well.
Eaddy BarnesConnect With a Mentor ITCommented:
the enter button is only having an effect because your still in the testing area of flash
if you run the swf directly ouside of flash it should work fine

as for clearing the data .. try

inputText.text = "";


Open in new window

Eaddy BarnesITCommented:
disregard the html tags  i think EE is bugging out

Jason210Author Commented:
Thanks....I wondered what you were talking about at first with "prettyprint" and what not...
I try it out tomorrow.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.