# Animate by increment and then change direction

**URL:** <https://forum.kirupa.com/t/animate-by-increment-and-then-change-direction/325984>\
**Category:** Uncategorized\
**Created:** [November 15, 2011, 3:41pm UTC](https://forum.kirupa.com/t/animate-by-increment-and-then-change-direction/325984 "2011-11-15T15:41:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bonassus](https://avatars.discourse-cdn.com/v4/letter/b/ea5d25/32.png) [@bonassus](https://forum.kirupa.com/u/bonassus)\
**Post date:** [November 15, 2011, 3:41pm UTC](https://forum.kirupa.com/t/animate-by-increment-and-then-change-direction/325984/1 "2011-11-15T15:41:28Z")

</div>

i’m trying to animate a movie clip by subtracting from its y value and then when it reaches a negative value change direction and animate by adding to its y value until it’s back to 0 and loop back and forth. what i have isn’t working.

```auto
 function Bodyloop(e:Event):void{

            var direction:Boolean;
           if(body.y > 0){
               direction = false;
           }
              if(body.y < -500){
                  direction = true;
           }

            if(direction == false){
             body.y -= 8;
            }else{
              body.y = (body.y + 8);
            }

        }

```

when it reaches -500 is jumps back and forth.  
what am i doing wrong. help appreciated

thanks!
