Animate by increment and then change direction

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.

 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!