# Mutiple intervals being created, Need one at a time?

**URL:** https://forum.kirupa.com/t/mutiple-intervals-being-created-need-one-at-a-time/268297
**Category:** flash
**Created:** [August 12, 2008, 11:54am UTC](https://forum.kirupa.com/t/mutiple-intervals-being-created-need-one-at-a-time/268297 "2008-08-12T11:54:50Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![scag](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@scag](https://forum.kirupa.com/u/scag)
#### Post date: [August 12, 2008, 11:54am UTC](https://forum.kirupa.com/t/mutiple-intervals-being-created-need-one-at-a-time/268297/1 "2008-08-12T11:54:50Z")

</div>

Hello  
Its seems a problem I am having is to do with setIntervals in a while loop. I clear what seems to be the interval but as another interval is started before the last one finish I then have multiple intervals.

I can close them all down with this…  
for (i= checkImage;i\>0;i–)  
{  
[INDENT] trace("clearInterval(checkImage) " +i);  
clearInterval(i);  
[/INDENT] }  
but that ofcourse closes the rest down before they have done what I need.

I think my while loop needs to change???  
Here is the current while loop code…

function loadImages()  
{  
[INDENT]while (imageWidthList[leftPictureNumber+imagesDisplayed] \> 0 and xPosition +(imageWidthList[leftPictureNumber+imagesDisplayed]+(borderThickness\*3)) \< 700)  
[/INDENT][INDENT] {  
[INDENT] var img\_mcl:MovieClipLoader = new MovieClipLoader();  
linkLayer = this.createEmptyMovieClip(“link”+(leftPictureNumber+imagesDisplayed), \_root.getNextHighestDepth());  
linkLayer.createEmptyMovieClip(“borderClip”, linkLayer.getNextHighestDepth());  
linkLayer.createEmptyMovieClip(“picture”, linkLayer.getNextHighestDepth());

```
    // give the link movie clip the x,y position. 
    // Anchors the whole picture and border to the x,y position
    linkLayer._y = yPosition;

```

linkLayer.\_x = xPosition;

xPosition = xPosition +(imageWidthList[leftPictureNumber+imagesDisplayed]+(borderThickness\*3));  
\_root.MoveRight.\_x = xPosition

img\_mcl.addListener(mclListener);  
checkImage = setInterval(watchMyImageLoad, 1000, img\_mcl, linkLayer.picture);  
img\_mcl.loadClip(imageNameList[leftPictureNumber+imagesDisplayed], linkLayer.picture);  
imagesDisplayed++;  
trace(“loadImages”);  
[/INDENT] }  
[/INDENT] } // function loadImages()

Is there a way that straight after the setInterval and the loadClip the function watchMyImageLoad is run to completion before continuing in the while loop.  
What i have seen is that the while loop continues until the condition has been met and then all the intervals are run???  
Is there a better way in doing this???
