# Altering x position of movie clip dynamically

**URL:** https://forum.kirupa.com/t/altering-x-position-of-movie-clip-dynamically/110390
**Category:** Uncategorized
**Created:** [May 15, 2004, 12:58pm UTC](https://forum.kirupa.com/t/altering-x-position-of-movie-clip-dynamically/110390 "2004-05-15T12:58:49Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![earleybird](https://avatars.discourse-cdn.com/v4/letter/e/a88e57/32.png) [@earleybird](https://forum.kirupa.com/u/earleybird)
#### Post date: [May 15, 2004, 12:58pm UTC](https://forum.kirupa.com/t/altering-x-position-of-movie-clip-dynamically/110390/1 "2004-05-15T12:58:49Z")

</div>

Hi,

I’ve built a little experiment which lets the user control a car with the fwd and bckwrd arrow keys. the idea is to move the car fwd but if it goes above a certain speed you have to slow it down. I have it working but the way i’ve done it is to move the backround to make it look like the car is moving. However, the backround can only be a certain width so atfer a while is moves clear of the screen. I’m trying to have it so that when the road’s \_x coordinate hits a certain point then it will jump back to its original point and the road will look like its just continuously moving. Here is the main code.

[color=blue]onClipEvent (load){  
//dir = 0;  
speed = 0;  
}[/color]  
[color=blue]onClipEvent (enterFrame) {  
xspeed = Math.cos(dir_Math.PI/180)speed;  
yspeed = Math.sin(dirMath.PI/180)speed;  
\_x += xspeed;  
\_y += yspeed;  
//\_rotation = dir; [/color]  
[color=blue]if (Key.isDown(Key.RIGHT)) {  
speed += -1;  
}  
if (speed\<=0){  
if (Key.isDown(Key.LEFT)) {  
speed += 1;  
}  
}  
[/color][color=blue][/color]  
[color=blue]if (speed\<0) {  
\_root.caption.carspeed = -1speed;  
}  
if (speed\>=0){  
\_root.caption.carspeed = 1_speed;  
}[/color]  
[color=#0000ff][/color]  
[color=blue]if (speed\<12){  
\_root.caption.health = “SAFE”;  
elseif (speed\>=12)  
\_root.caption.health = “DANGER”;  
}[/color]  
[color=#0000ff][/color]  
[color=black]This is the bit where I tried to get the \_x value to change:[/color]  
[color=blue][/color]  
[color=red]if(\_x==(-3104)){  
\_x =+ 3104;  
}[/color]

[color=blue]}[/color]

I’ve attatched my .fla to help explain!  
[color=#0000ff][/color]  
[color=black]I think i’m totally wrong and would greatly appreciate some help![/color]  
🙂
