# Help with for loop for prev and next frames

**URL:** <https://forum.kirupa.com/t/help-with-for-loop-for-prev-and-next-frames/179890>\
**Category:** Uncategorized\
**Created:** [February 23, 2006, 8:28pm UTC](https://forum.kirupa.com/t/help-with-for-loop-for-prev-and-next-frames/179890 "2006-02-23T20:28:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![S34N](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/s34n/32/2149_2.png) [@S34N](https://forum.kirupa.com/u/S34N)\
**Post date:** [February 23, 2006, 8:28pm UTC](https://forum.kirupa.com/t/help-with-for-loop-for-prev-and-next-frames/179890/1 "2006-02-23T20:28:08Z")

</div>

I’m trying to animate a fader along a motion path (each frame has a stop in the actions layer and there are 30 frames total). I want to be able to find what the currentFrame is and pass a targetFrame … then have a for loop move to the prevFrame/nextFrame arcordingly. I think I’m just getting turned around in the for loop right now. Been a long time since I’ve written one. I could be going about this all wrong but the jist is that I have a mixing console and I’ve got some faders (movieclips) on it and they are all on motion guides (so they stay where they are supposed too). I want to be able to make each one move to a certain place when a button is clicked (so I was thinking of making the above into a class)

Well I did some fiddling around and here’s what I have thus far:

```auto
var currentFrame = 0;
var targetFrame = 0;
var newTargetFrame = 0;
//of course I will have to pass in some of these values(working on that)
//current and target frames are the same
if (currentFrame == targetFrame){
this.stop();
}
//moving backwards from curent to target frame
if (currentFrame > targetFrame){
newTargetFrame = currentFrame - targetFrame; 
for (i=0; i<newTargetFrame; i++){
this.prevFrame();
}
currentFrame = targetFrame;
}
//moving forwards from current frame to target frame
if (currentFrame > targetFrame){
newTragetFrame = currentFrame + targetFrame;
for (i=0; i>newTargetFrame; i++){
this.netFrame();
}
currentFrame = targetFrame;
}

```

Well so much for that ☹ I can’t figure out what I’m doing wrong … do I need more code than this? if I set the newTarget to 15 nothing happens
