Counting # of times user press Enter

Hi Everyone, I’m having trouble determining how I can create a counter where if the user presses the Enter key 3 times, it automatically takes the user to the next frame. It’s relatively simple, I know, but I’m having trouble beginning. Any help would be greatly appreciated!

forgot to mention I’m using AS3.

Can you share what you have so far? Also, is it when they hit enter 3 times consecutively or 3 times period?

Hi, thanks for responding. I’m having difficulty starting so far. It is consecutively.

Robert.

Here is some annotated code that should help:

import flash.events.KeyboardEvent;
import flash.ui.Keyboard;

// stop at this keyframe
stop();

// keeps track of how many times the ENTER
// key is pressed
var enterKeyCount = 0;

// run the handleKeyUp function whenever a key
// is pressed, specifically when released.
// state is used so it captures all key presses
// in the SWF and not just those for when a 
// specific object is focused
stage.addEventListener(KeyboardEvent.KEY_UP, handleKeyUp);

// function to be called when key is pressed
function handleKeyUp(event:KeyboardEvent):void {
	
	// if the key being pressed is the enter key...
	if (event.charCode === Keyboard.ENTER) {
		
		// update the count by one
		enterKeyCount++;
		
		// if the count matches 3, then we go
		// to the next frame and stop. If we want
		// to go to the next frame and play, then
		// we would just use play()
		if (enterKeyCount === 3) {
			nextFrame();
		}
		
	}else{
		
		// we want 3 consecutive ENTER keys to cause
		// us to move to the next frame so if a key
		// is pressed that isnt ENTER, we reset the counter
		enterKeyCount = 0;
	}
}

Note: There might be some weirdness testing in Flash itself because of what ENTER means as a shortcut there. I think if you use “Debug movie” instead of “Test movie” if fixes this.

issuing-refund-scenario1.zip (2.9 MB)
Hi, I placed the code into the flash file and it’s not working correctly. Could you please take a quick look at the file and let me know what I’m doing wrong. After the frame where the user has to type in several input text fields, the user must press Enter 3 times to get the last frame. I originally had 3 of the same screen shot and used a simple enter function to move to the next frame, which wouldn’t work.

Any help you can provide would be greatly appreciated. Thanks!!!