# AS2 animation loop problem

**URL:** https://forum.kirupa.com/t/as2-animation-loop-problem/332417
**Category:** flash
**Created:** [June 2, 2014, 6:00am UTC](https://forum.kirupa.com/t/as2-animation-loop-problem/332417 "2014-06-02T06:00:49Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![rik\_na1](https://avatars.discourse-cdn.com/v4/letter/r/a87d85/32.png) [@rik\_na1](https://forum.kirupa.com/u/rik_na1)
#### Post date: [June 2, 2014, 6:00am UTC](https://forum.kirupa.com/t/as2-animation-loop-problem/332417/1 "2014-06-02T06:00:49Z")

</div>

I am trying to make a simple animation that goes right 20px, then left 20px in an infinite loop. I have got so far:

```
    onClipEvent (load) {
  speed = 3
} 
onClipEvent (enterFrame) {
   if(this._x &lt; 20){
     this._x += speed;
 } else {
     speed = -3
} 
    this._x += speed;
   }

```

But I have two problems largely because I am not very good at AS2. The loop goes to the right and back to the left that is fine. But I cannot work out how to limit the left animation to 20px and then get it to repeat to inifinity. I know this is simple but it is beyond me. Can anyone help?

---

<div class="post-metadata">

### Author: ![bbpanzu](https://avatars.discourse-cdn.com/v4/letter/b/f19dbf/32.png) [@bbpanzu](https://forum.kirupa.com/u/bbpanzu)
#### Post date: [September 5, 2017, 2:15am UTC](https://forum.kirupa.com/t/as2-animation-loop-problem/332417/2 "2017-09-05T02:15:44Z")

</div>

put

onClipEvent(keyUp){  
stop();  
}

on the loop.
