Link to home
Start Free TrialLog in
Avatar of Jason210
Jason210Flag for Sweden

asked on

Input Text problem, ActionScript 3.0

Hi

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?
stop();
 
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
		}
		else
		{
		trace("accepted: "+inputText.text);
		gotoAndStop(3);//starts movie
		}
	}
}
 
trace ("Outside conditionalas: inputText.text = "+inputText.text)

Open in new window

SOLUTION
Avatar of Eaddy Barnes
Eaddy Barnes
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
disregard the html tags  i think EE is bugging out

GE
Avatar of Jason210

ASKER

Thanks....I wondered what you were talking about at first with "prettyprint" and what not...
I try it out tomorrow.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial