Input Text problem, ActionScript 3.0

Posted on 2009-02-24
Last Modified: 2012-08-14

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

Question by:Jason210
    LVL 11

    Assisted Solution

    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

    LVL 11

    Expert Comment

    disregard the html tags  i think EE is bugging out

    LVL 11

    Author Comment

    Thanks....I wondered what you were talking about at first with "prettyprint" and what not...
    I try it out tomorrow.
    LVL 1

    Accepted Solution

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
    While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
    In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
    This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now