# Repeating a line of code or infinate prevFrame

**URL:** <https://forum.kirupa.com/t/repeating-a-line-of-code-or-infinate-prevframe/261042>\
**Category:** Uncategorized\
**Created:** [May 22, 2008, 10:26am UTC](https://forum.kirupa.com/t/repeating-a-line-of-code-or-infinate-prevframe/261042 "2008-05-22T10:26:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alfandango](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@alfandango](https://forum.kirupa.com/u/alfandango)\
**Post date:** [May 22, 2008, 10:26am UTC](https://forum.kirupa.com/t/repeating-a-line-of-code-or-infinate-prevframe/261042/1 "2008-05-22T10:26:48Z")

</div>

Hey,

I’m trying to create a movie clip that can be controlled to move a shape left or right (as animated in the movie clip) via buttons on the main stage.

I was thinking I could just add prevFrame or nextFrame to the controlling buttons when the mouse rolls over them… like this:

[LEFT]

```auto
on (rollOver) {
    this.shape.prevFrame();
}

```

[/LEFT]

[FONT=monospace]  
[/FONT]But now I need a method of repeating it non-stop while you are on the button. Can I loop the prevFrame infinatly or loop that line of code? Any ideas?

P.S I’m just getting to grips with actionscript and I’m hitting a few hurdles on the way, so please excuse my ignorance.

Al

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [May 22, 2008, 4:35pm UTC](https://forum.kirupa.com/t/repeating-a-line-of-code-or-infinate-prevframe/261042/2 "2008-05-22T16:35:58Z")

</div>

The answer is right under your nose, a few threads lower down:

> **[prevframe error/question](https://www.kirupa.com/forum/showthread.php?t=298550)**
>
> Got a web design/development question or just want to hang out with the most awesome people on the planet? Drop on in!

---

<div class="post-metadata">

**Author:** ![alfandango](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@alfandango](https://forum.kirupa.com/u/alfandango)\
**Post date:** [May 22, 2008, 5:09pm UTC](https://forum.kirupa.com/t/repeating-a-line-of-code-or-infinate-prevframe/261042/3 "2008-05-22T17:09:17Z")

</div>

cheers mate, I’m almost there 🙂

…Just one question. If the buttons are controlling a movie clip with the instance name “shape”, how would I control that? I’ve tried changing the code you suggested (as seen below) but my action script isn’t quite there yet ☹

```auto
[COLOR=#808080]*// place this code on your main timeline*[/COLOR]
[LEFT] rewind = [COLOR=#000000] **false** [/COLOR];
[COLOR=#0000ff]onEnterFrame[/COLOR] = [COLOR=#000000] **function** [/COLOR] [COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
    [COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000ff]_root[/COLOR].[COLOR=#0000ff]_currentframe[/COLOR] > [COLOR=#000080]1[/COLOR] && rewind[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
        [COLOR=#0000ff]_root[/COLOR].[COLOR=#0000ff]prevFrame[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
    [COLOR=#000000]}[/COLOR] [COLOR=#0000ff]else[/COLOR] [COLOR=#000000]{[/COLOR]
        [COLOR=#0000ff]play[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
    [COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR];
[COLOR=#808080]*// place this code on your rewind arrow*[/COLOR]
[COLOR=#0000ff]on[/COLOR] [COLOR=#000000]([/COLOR]press[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
    [COLOR=#0000ff]_root[/COLOR].[COLOR=#000080]rewind[/COLOR] = [COLOR=#000000] **true** [/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#0000ff]on[/COLOR] [COLOR=#000000]([/COLOR]release[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
    [COLOR=#0000ff]_root[/COLOR].[COLOR=#000080]rewind[/COLOR] = [COLOR=#000000] **false** [/COLOR];
[COLOR=#000000]}[/COLOR] 

```

[/LEFT]

The code I’m using for the forward button is as follows and I’m quite happy with that one, basically I need the opposite on the backwards button:

```auto
on (rollOver) {
    this.shape.play();
}

on (rollOut) {
    this.shape.stop();
}

```

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [May 22, 2008, 8:15pm UTC](https://forum.kirupa.com/t/repeating-a-line-of-code-or-infinate-prevframe/261042/4 "2008-05-22T20:15:19Z")

</div>

Without knowing the exact layout of your fla, I’d suggest changing \_root.currentFrame and \_root.prevFrame to shape.currentFrame and shape.prevFrame. Also change press and release to rollOver and rollOut if that’s what you want.

---

<div class="post-metadata">

**Author:** ![nathan99](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@nathan99](https://forum.kirupa.com/u/nathan99)\
**Post date:** [May 23, 2008, 3:07pm UTC](https://forum.kirupa.com/t/repeating-a-line-of-code-or-infinate-prevframe/261042/5 "2008-05-23T15:07:35Z")

</div>

```auto
// place this code on your main timeline
 rewind = false;
onEnterFrame = function () {
    if (_root._currentframe > 1 && rewind) {
        shape.prevFrame();
    } else {
        play();
    }
};
// place this code on your rewind arrow
on (press) {
    _root.rewind = true;
}
on (release) {
    _root.rewind = false;
} 

```

😕
