If/else statements to move clip relative to variable

I have a clip that I want to move up and down relative to a variable, clipLocation. The clip will move down but when it is supposed to stop, it just toggles up 1 and down 1 in a loop. The solution has to be obvious but I can’t put my finger on it. Here is the code.

function resizeDefinitionField() {
_root.defs._y = _root.context_txt._height+_root.context_txt._y+10;
_root.defs.definition_txt.autoSize = true;
    this.onEnterFrame = function () {
        clipLocation = _root.defs._y+_root.defs._height+10;
 
            if (this._y < clipLocation) {
 
            this._y += 1;
 
        } else if (this._y > clipLocation) {
 
            this._y -= 1;
 
 
        } else {
 
            this._y = clipLocation;
 
        }
      }
    }

There is probably a little bit better way to write the entire function, but putting this line in it should stop the loop.
Nice to see another Missouri boy in the forum :smiley:


function resizeDefinitionField() {
_root.defs._y = _root.context_txt._height+_root.context_txt._y+10;
_root.defs.definition_txt.autoSize = true;
    this.onEnterFrame = function () {
        clipLocation = _root.defs._y+_root.defs._height+10;
 
            if (this._y < clipLocation) {
 
            this._y += 1;
 
        } else if (this._y > clipLocation) {
 
            this._y -= 1;
 
 
        } else {
 
            this._y = clipLocation;
           ** delete.this.onEnterFrame; ** 
        }
      }

    }

OK, thank you for replying. I tried to the delete operator like you suggested and it didn’t work. Do you think I should try to rewrite this as a do/while loop?