Skip to main content
Inspiring
May 4, 2006
Answered

Controling nextFrame() & prevFrame()

  • May 4, 2006
  • 2 replies
  • 416 views
I am using this code to allow for the right and left key to jump one frame forward or backward

var keyListener bject = new Object;

keyListener.onKeyDown = function():Void {
if (Key.isDown(Key.RIGHT)) {
if (_root._currentframe < 8){
nextFrame();
}
} else if (Key.isDown(Key.LEFT)){
if (_root._currentframe > 1){
prevFrame();
}
}
};

Key.addListener(keyListener)
stop();

The problem I am having is when you press the right key (Key.RIGHT) it moves to the 2nd frame. If I then press the left key (Key.LEFT) to go back a frame then press the right key again the movie jump to frame 3 skipping frame two. This continues until there are no more frames to go to and then the left and right key press toggle between the first frame and the last frame. I need to control the nextFrame() and prevFrame method so that when pressed either forward or backward it only goes to the very next frame or the previous frame. Does anyone know how to control the two methods?

I hope this makes sense.

Thanks,

Kyle
This topic has been closed for replies.
Correct answer shyaway
stop();

if (init == undefined) {
someListener = new Object();
someListener.onKeyDown = function() {
if (Key.isDown(Key.LEFT) || Key.isDown(Key.UP)) {
_level0.prevFrame();
} else if (Key.isDown(Key.RIGHT) || Key.isDown(Key.DOWN)) {
_level0.nextFrame();
}
};
Key.addListener(someListener);
init = 1;
}

pasted from help file.

2 replies

kypsulAuthor
Inspiring
May 4, 2006
THANK YOU!!!! That worked perfectly.
shyawayCorrect answer
Participating Frequently
May 4, 2006
stop();

if (init == undefined) {
someListener = new Object();
someListener.onKeyDown = function() {
if (Key.isDown(Key.LEFT) || Key.isDown(Key.UP)) {
_level0.prevFrame();
} else if (Key.isDown(Key.RIGHT) || Key.isDown(Key.DOWN)) {
_level0.nextFrame();
}
};
Key.addListener(someListener);
init = 1;
}

pasted from help file.