Reputation: 1
trying to make a simple comic in flash. press the left or right arrow key and you go to the next frame of the comic. problem is I press down the right key once and it cycles through the whole comic in an instant.
frame 1
stop();
onEnterFrame = function(){
if(Key.isDown(Key.RIGHT))
{
gotoAndStop(2);
}
}
frame 2
stop() ;
onEnterFrame = function(){
if(Key.isDown(Key.RIGHT))
{
gotoAndStop(3);
}
if(Key.isDown(Key.LEFT))
{
gotoAndStop(1);
}
}
and so on and so on
how do I make it so you press the right key and it just goes to frame 2 and stops, and only goes to frame 3 once you've taken your finger off the right key and pressed it again?
Upvotes: 0
Views: 148
Reputation: 7316
Forgive my rusty AS2, more than 10 years passed since I last used it seriously, but the logic behind it should be solid. You need a flag for both keys to keep track if they were pressed previously or not, then you should browse pages left or right only when the relevant key wasn't pressed last time, but now is.
// Frame 1. You only need this script, it will serve
// the whole timeline. You don't need other scripts on other frames.
// These are flags to know, if the relevant keys was pressed previously.
var wasLeft:Boolean;
var wasRight:Boolean;
function onEnterFrame()
{
var isLeft:Boolean = Key.isDown(Key.LEFT);
var isRight:Boolean = Key.isDown(Key.RIGHT);
// Move to the previous page only if
// the LEFT key is but wasn't pressed
// and also if the other button is up.
if (isLeft && !wasLeft && !isRight)
{
prevFrame();
}
// The same routine for the other key.
if (isRight && !wasRight && !isLeft)
{
nextFrame();
}
// Keep the present state of things for the next frame call.
wasLeft = isLeft;
wasRight = isRight;
}
Upvotes: 0