dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [CS3] Can't figure out Enter key in AS 2

Hybrid View

  1. #1
    Junior Member
    Join Date
    Mar 2002
    Posts
    27

    [CS3] Can't figure out Enter key in AS 2

    Hey guys. I am hoping this is simple but I am stumped. I've checked online and google'd this for a few days but haven't found the answer. I actually found a site that said it had the answer but I had to pay money to sign up as a "premium" member which I didn't really think is worth it.

    My problem is that I have a frame that has no buttons or movie clips, just a picture and input text boxes. I want the enter key to move to the next frame when pressed if the conditions are met (ie if the username is correct). I don't even know where to start. I've tried several random codes and created invisible movie clips for those codes but nothing has worked. I won't post those codes because they are so far off that it might confuse someone into helping me why that specific code doesn't work.

    Let me know if you need any info.

    Example:

    Have a username input text box where if you type the correct username and press the Enter button it will take you to frame 2. If you type the incorrect name it will stay the same.

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    on stage - input textfield - instance name - username
    code on frame#1 -
    PHP Code:
    keyWatch = new Object();
    Key.addListener(keyWatch);

    keyWatch.onKeyDown = function(){
    if(
    Key.getCode() == key.ENTER && username.text == "bob"){
    gotoAndStop(2);
    }
    }; 

  3. #3
    Junior Member
    Join Date
    Mar 2002
    Posts
    27
    First I want to thank you both for the very quick responses Thats why I <3 this site.

    Second, at first I was having problems with a_modified_dog's coding and couldn't figure it out. So I went to try gparis but noticed in his the username instance name is lower case and my instance was Username. So I went back and checked a_modified_dog's coding again and noticed his was also username. So I changed the coding and it appears to be working!

    Thank you so much guys, you are the greatest

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    input textfield with instance name 'username'

    PHP Code:
    username.text "";

    var 
    myListener:Object = new Object();
    myListener.onKeyDown = function () {
        if (
    username.text.length && Key.isDown(Key.ENTER)) {
            
    nextFrame();
        } else {
            
    trace("empty");
         }
    }

    Key.addListener(myListener); 
    gparis

  5. #5
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    beat me to it

    gparis

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center