# SetInterval on attachmovie function with x and y loc

**URL:** <https://forum.kirupa.com/t/setinterval-on-attachmovie-function-with-x-and-y-loc/258821>\
**Category:** flash\
**Created:** [April 28, 2008, 5:18pm UTC](https://forum.kirupa.com/t/setinterval-on-attachmovie-function-with-x-and-y-loc/258821 "2008-04-28T17:18:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![karkaim](https://avatars.discourse-cdn.com/v4/letter/k/f17d59/32.png) [@karkaim](https://forum.kirupa.com/u/karkaim)\
**Post date:** [April 28, 2008, 5:18pm UTC](https://forum.kirupa.com/t/setinterval-on-attachmovie-function-with-x-and-y-loc/258821/1 "2008-04-28T17:18:34Z")

</div>

HI. I’m new here. I have a function on my script that attaches a movieclip on a specific position and then it duplicates it several times. This movieclip has a code in order to move across the stage randomly. When I try to use SetInterval to repeat this function two weird things happen: the movieclips don’t duplicate over that specific location (they appear on x=0,y=0) and if I set the location only one duplicates and the rest don’t. My question is: what can I do to repeat the function every 2 seconds exactly as it is the first time it runs, without the objects not duplicating or moving from the original location?

Here’s the code:

meteoros = function () {  
this.attachMovie(“asteroid”,“asteroid\_mc”,this.getNextHighestDepth());  
asteroid\_mc.\_x = 470;  
asteroid\_mc.\_y = 70;  
//i++;  
while (i\<5) {  
this.asteroid\_mc.duplicateMovieClip(“asteroid\_mc”+i,this.getNextHighestDepth());  
i++;  
}

};

setInterval(this,“meteoros”,2000);
