# Intervals using relative object positioning?

**URL:** https://forum.kirupa.com/t/intervals-using-relative-object-positioning/216777
**Category:** Uncategorized
**Created:** [February 20, 2007, 2:01pm UTC](https://forum.kirupa.com/t/intervals-using-relative-object-positioning/216777 "2007-02-20T14:01:15Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![kingscooty](https://avatars.discourse-cdn.com/v4/letter/k/73ab20/32.png) [@kingscooty](https://forum.kirupa.com/u/kingscooty)
#### Post date: [February 20, 2007, 2:01pm UTC](https://forum.kirupa.com/t/intervals-using-relative-object-positioning/216777/1 "2007-02-20T14:01:15Z")

</div>

Hey guys check this code out:

[AS]  
function moveClip() {

if (myClip\_mc.\_x \< 400) {

```
// the _x value is less than 400, so increase _x by 1px,

// and let setInterval execute this function again

myClip_mc._x += 1; // move the clip 1 px to the right

```

} else {

```
// the _x value is greater than 400, 

// so stop the setInterval from executing anymore

clearInterval(myInterval);

```

} // end “if myClip\_mc.\_x \< 400”

} // end moveClip()

// do this when “myButton\_btn” is clicked

myButton\_btn.onPress = function() {

// execute the “moveClip” function every 10 milliseconds

myInterval = setInterval(moveClip, 5);

} // end myButton\_btn.onPress()  
[/AS]

I was wondering, is there a way to change **if (myClip\_mc.\_x \< 400) {** to a relative position of myClip\_mc.  
I mean, i want myClip\_mc to move 100px from **it’s current** position everytime the button is clicked. Instead of only moving it  
if it’s x position is less than 400.  
So it needs to somehow check it’s current position everytime the button is clicked and then make it shift from that position.

I know this is a long winded way of doing it but i want it this way so i can use it for something different.

Any ideas? 🙂
