# If/else statements to move clip relative to variable

**URL:** <https://forum.kirupa.com/t/if-else-statements-to-move-clip-relative-to-variable/188914>\
**Category:** Uncategorized\
**Created:** [May 11, 2006, 7:52pm UTC](https://forum.kirupa.com/t/if-else-statements-to-move-clip-relative-to-variable/188914 "2006-05-11T19:52:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sparky\_J](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@Sparky\_J](https://forum.kirupa.com/u/Sparky_J)\
**Post date:** [May 11, 2006, 7:52pm UTC](https://forum.kirupa.com/t/if-else-statements-to-move-clip-relative-to-variable/188914/1 "2006-05-11T19:52:48Z")

</div>

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.

```auto
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;
 
        }
      }
    }

```

---

<div class="post-metadata">

**Author:** ![Gumby19](https://avatars.discourse-cdn.com/v4/letter/g/3da27b/32.png) [@Gumby19](https://forum.kirupa.com/u/Gumby19)\
**Post date:** [May 11, 2006, 9:07pm UTC](https://forum.kirupa.com/t/if-else-statements-to-move-clip-relative-to-variable/188914/2 "2006-05-11T21:07:19Z")

</div>

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 😃

```auto

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;** 
        }
      }

    }

```

---

<div class="post-metadata">

**Author:** ![Sparky\_J](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@Sparky\_J](https://forum.kirupa.com/u/Sparky_J)\
**Post date:** [May 11, 2006, 9:18pm UTC](https://forum.kirupa.com/t/if-else-statements-to-move-clip-relative-to-variable/188914/3 "2006-05-11T21:18:15Z")

</div>

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?
