# Moving movie clip

**URL:** <https://forum.kirupa.com/t/moving-movie-clip/21385>\
**Category:** Uncategorized\
**Created:** [May 21, 2003, 4:37am UTC](https://forum.kirupa.com/t/moving-movie-clip/21385 "2003-05-21T04:37:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![zephn](https://avatars.discourse-cdn.com/v4/letter/z/5f8ce5/32.png) [@zephn](https://forum.kirupa.com/u/zephn)\
**Post date:** [May 21, 2003, 4:37am UTC](https://forum.kirupa.com/t/moving-movie-clip/21385/1 "2003-05-21T04:37:00Z")

</div>

ok it’s simple as hell but I can’t seem to do it.  
I have a movie clip I want to move back and forth between 200 pixels and 600… this is the code i scripted fomr scratch and it doens’t seem to be working for me, it gets to 600 then drops below 600 and doens’t slide back to 200. What can I do?

onClipEvent(enterFrame) {  
speed = 3.5;

if (this.\_x\>600){  
this.\_x -= speed;  
}  
else {  
this.\_x += speed;  
}  
}

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 21, 2003, 4:40am UTC](https://forum.kirupa.com/t/moving-movie-clip/21385/2 "2003-05-21T04:40:42Z")

</div>

I hate how you hate hockey…  
[AS]  
onClipEvent(load){  
\_x=200;  
speed=5;  
}  
onClipEvent(enterFrame){  
\_x+=speed;  
if(\_x\>=600 or \_x\<=200){  
speed\*=-1;  
}  
}  
[/AS]

Give that a shot.  
(-:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 21, 2003, 4:42am UTC](https://forum.kirupa.com/t/moving-movie-clip/21385/3 "2003-05-21T04:42:34Z")

</div>

to be specific I just don’t watch it. Hating takes effort and I don’t put any effort anywhere when it comes to hockey hehe and thank you for the help, it works like a charm.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 21, 2003, 4:42am UTC](https://forum.kirupa.com/t/moving-movie-clip/21385/4 "2003-05-21T04:42:53Z")

</div>

you need to keep track of which way the clip is movingm or when it is halfway between 200 and 600 it wont know which way to go

so  
var direction=1;

onClipEvent(enterFrame) {  
speed = 3.5;

if (this.\_x\>600){  
direction = -1;  
}  
else if (this.\_x\<200){  
direction = 1;  
}  
\when it is between 200 and 600 neither if statement executes  
\so direction remains whatever it just was

this.\_x+=speed\*direction;

\speed += a negative number instead of -=  
\when direction is -1

}

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 21, 2003, 4:43am UTC](https://forum.kirupa.com/t/moving-movie-clip/21385/5 "2003-05-21T04:43:53Z")

</div>

oops I said exaclty the same thing  
HA! thats great freddy

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 21, 2003, 4:52am UTC](https://forum.kirupa.com/t/moving-movie-clip/21385/6 "2003-05-21T04:52:17Z")

</div>

correct me if i’m wrong freddie if this it what happens  
x starts at 200  
speed is 5  
every frame x is equal to x+ speed or in this case 5  
my mc is moving it is moving 5 pixels at a time  
if x\>600 or x\<200 it makes speed \*= -1  
when it reaches 600 it multiplies it by -1 making speed -5  
speed is now -5 so the x begins to backstep 5 at a time.  
when it reaches 200 it again multiplies speed by -1 making it positive 5  
and so on and so on

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 21, 2003, 4:53am UTC](https://forum.kirupa.com/t/moving-movie-clip/21385/7 "2003-05-21T04:53:08Z")

</div>

I understood your code right away clownstaples and thank you for that version. Freddies was a bit more complicated to translate but i think i got it

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 21, 2003, 5:01am UTC](https://forum.kirupa.com/t/moving-movie-clip/21385/8 "2003-05-21T05:01:11Z")

</div>

It’s because you don’t watch hockey! Just kidding. To each his own. Read through the last post you wrote to me…My immediate responce in my head was, “exactly”. ‘Speed’ you change to tell how many pixels per loop to travel. When it hits the boundries (200/600) it changes the +/- of the variable ‘speed’; so hence changing the direction. It is a touch complicated. I got it from bit-101 months ago and now it’s all I use.  
Saying it’s complicted is the best compliment I’ve had today!! Thanks :beam:
