-
[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.
-
FK'n_dog
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);
}
};
-
input textfield with instance name 'username'
PHP Code:
username.text = "";
var myListener:Object = new Object();
myListener.onKeyDown = function () {
if (username.text.length > 0 && Key.isDown(Key.ENTER)) {
nextFrame();
} else {
trace("empty");
}
}
Key.addListener(myListener);
gparis
-
beat me to it
gparis
-
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|