# Repeating code

**URL:** <https://forum.kirupa.com/t/repeating-code/259891>\
**Category:** flash\
**Created:** [May 9, 2008, 8:01pm UTC](https://forum.kirupa.com/t/repeating-code/259891 "2008-05-09T20:01:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tile\_nipper](https://avatars.discourse-cdn.com/v4/letter/t/e8c25b/32.png) [@tile\_nipper](https://forum.kirupa.com/u/tile_nipper)\
**Post date:** [May 9, 2008, 8:01pm UTC](https://forum.kirupa.com/t/repeating-code/259891/1 "2008-05-09T20:01:52Z")

</div>

I can’t figure out how to use if/else and setInterval statements on the cross fade slideshow. I am trying to edit the code to have the xml slideshow loop back to the first image and play continuously. I am ok following existing code, not great at writing/editing my own. I thought I needed to work within the nextImage function, and add a slideshow (); function. I haven’t been able to get it right. Here is the code minus the xml loading part:

var id, current;  
var k = 0, p = 0;  
var slide = 1;

function preloadPic() {  
clearInterval(id);  
var con = picture.duplicateMovieClip(“con”+k, 9984+k);  
con.loadMovie(image[p]);  
preloader.\_visible = 1;  
preloader.swapDepths(con.getDepth()+3);  
con.\_alpha = 0;  
var temp = \_root.createEmptyMovieClip(“temp”+k, 99+k);  
k++;  
temp.onEnterFrame = function() {  
var total = con.getBytesTotal();  
var loaded = con.getBytesLoaded();  
percent = Math.round(loaded/total\*100);  
preloader.preload\_bar.\_xscale = percent;  
if (con.\_width) {  
preloader.\_visible = 0;  
con.onEnterFrame = fadeIn;  
if (slide) {  
id = setInterval(nextImage, 1000);  
}  
delete this.onEnterFrame;  
}  
};  
}

MovieClip.prototype.fadeIn = function() {  
if (this.\_alpha\<100) {  
current.\_alpha -= 10;  
this.\_alpha += 10;  
} else {  
current.\_visible = 0;  
current = this;  
delete this.onEnterFrame;  
}  
};

function nextImage() {  
if (p\<(total-1)) {  
p++;  
preloadPic();  
} else {  
p=0;  
preloadPic();  
}  
}

---

<div class="post-metadata">

**Author:** ![tile\_nipper](https://avatars.discourse-cdn.com/v4/letter/t/e8c25b/32.png) [@tile\_nipper](https://forum.kirupa.com/u/tile_nipper)\
**Post date:** [May 9, 2008, 8:15pm UTC](https://forum.kirupa.com/t/repeating-code/259891/2 "2008-05-09T20:15:06Z")

</div>

Disregard. The code is working fine. Loops and all. I have no idea what I did, but I wasted all morning on it. Sigh.
