# How can I make my mc moving across the page in a loop?

**URL:** <https://forum.kirupa.com/t/how-can-i-make-my-mc-moving-across-the-page-in-a-loop/321331>\
**Category:** flash\
**Created:** [April 16, 2011, 11:30pm UTC](https://forum.kirupa.com/t/how-can-i-make-my-mc-moving-across-the-page-in-a-loop/321331 "2011-04-16T23:30:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chbook](https://avatars.discourse-cdn.com/v4/letter/c/82dd89/32.png) [@Chbook](https://forum.kirupa.com/u/Chbook)\
**Post date:** [April 16, 2011, 11:30pm UTC](https://forum.kirupa.com/t/how-can-i-make-my-mc-moving-across-the-page-in-a-loop/321331/1 "2011-04-16T23:30:54Z")

</div>

Hi, I am trying to make a simulation of a blood moving in an artery and I want blood cells to continuously be moving across the stage ( so that there are no gaps in between one loop and the other) when i click the start button.  
I thought about doing a setinterval loop but it just overwrites the previous set of generated mcs?

This is the code on my button  
on (release) {  
var years:Number = 80;   
function generatePlatelet (){  
var Platelet\_no:Number = PlateletStepper.value;   
for (var count:Number = 0; count\<Platelet\_no; count++){  
\_root.Platelet.duplicateMovieClip (“Platelet” + count, count);  
}

}  
generatePlatelet();  
}

And this is the code in my blood cell(platelet)  
onClipEvent (load) {  
gravity = 0.01;  
xspeed = 10;  
}

onClipEvent(load){  
Position\_y = Math.random () \* 125 + 5  
Position\_x = Math.random () \* 755 + 5

\_x = Position\_x  
\_y= Position\_y  
}  
onClipEvent (enterFrame) {

```
	xspeed += gravity;
	while (_root.terrain.hitTest(_x, _y+_height, true)) {
		_x--;
		xspeed = 0;
	}
	if (!_root.terrain.hitTest(_x, _y+_height+1, true)) {
		_x -= xspeed;
	} else {
		xspeed = 0;
	}

```

}
