If you’re doing everything manually on the timeline, then you don’t have to worry about setInterval. What setInterval does for you is give you a dynamic, code-controlled version of that timeline allowing you to easily - through code - have adjustments in timing and count. This means you could have a potentially infinitely long game that progressively gets longer (more keys) but also faster (shorter time between keys). It could also be randomly generated so that its different every time you play.
On the timeline you’re fixed with what you have. And that’s fine. Its more work and harder to maintain, but if you’re up for the work (which you said you are), it will be more straightforward to complete
Ultimately the concept is the same. For each phase you have key listeners set up to detect the appropriate key. At the start of a key window, you need to set up which key to look for. This can be just a variable to detect in the key listener. When a key is pressed (key listener) you determine if its right or wrong. If right, you can let it continue until the next set up frame, but if wrong, you do some clean up (remove key listeners) and go to the failure frame. At the last frame of a group of arrows, you have your victory.
So imagine this timeline:
[a]---[b]---[c]---[d]-[W]-[L]
a-d represents your phase, a-c being starts of a key window and d being the end of the last window ©. The W frame is the frame for winners and L the frame for losers.
a is where you set up your key listener. In W and L you’ll need to remove the listener because thats the end of the game and its no longer needed. In a, b, and c you need to define what key your key listener needs to listen for. The key listener itself will check the key pressed with what you defined here. You also need to track if any key was pressed, and clear that out once a key is pressed. Because what if someone doesn’t press a key between a and b? So, b, c and d each need to check to see if a key was not pressed and go to L if that was the case since they also represent the end of a key window. Here’s what I imagine frame a to look like:
// frame a
setupListeners();
setExpectedKey(Keyboard.LEFT, false);
frame b might be
// frame b
validateKeyPressed();
setExpectedKey(Keyboard.UP, false);
and c (similar to b) would look something like
// frame c
validateKeyPressed();
setExpectedKey(Keyboard.RIGHT, true);
while d is just
// frame d
validateKeyPressed();
both W and L would include
cleanupListeners();
What are these functions? (And yes, functions are preferred instead of a bunch of code since you’re going to have a lot of these frames). They’d be defined in frame one of your timeline (and therefore accessible everywhere) look something like
var expectedKey = -1; // key code for each window to be checked
var isLast = false; // lets us know if we go on to win on the last key window
var keyWasPressed = false; // lets us know if no key was pressed
function setupListeners() {
stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
}
function cleanupListeners() {
stage.removeEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
}
function setExpectedKey(expectedKey, isLast) {
this.expectedKey = expectedKey;
this.isLast = isLast;
this.keyWasPressed = false;
}
function handleKeyDown(event:KeyboardEvent) {
this.keyWasPressed = true;
if (event.keyCode !== this.expectedKey) {
gotoAndStop("L");
}else if (this.isLast) {
gotoAndStop("W");
}
}
function validateKeyPressed() {
if (!this.keyWasPressed) {
gotoAndStop("L");
}
}
This is all off the top of my head, so probably won’t work, but it will give you an idea of where to go.