• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 619
  • Last Modified:

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

0
Jason210
Asked:
Jason210
  • 2
2 Solutions
 
Eaddy BarnesITCommented:
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 = "";

GE

Open in new window

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

GE
0
 
Jason210Author Commented:
Thanks....I wondered what you were talking about at first with "prettyprint" and what not...
I try it out tomorrow.
0
 
FlyingFlashCommented:
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.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now