AS2 animation loop problem


#1

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 < 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?


#2

put

onClipEvent(keyUp){
stop();
}

on the loop.