# Image Loader Gallery

**URL:** <https://forum.kirupa.com/t/image-loader-gallery/308833>\
**Category:** flash\
**Created:** [May 1, 2010, 3:36am UTC](https://forum.kirupa.com/t/image-loader-gallery/308833 "2010-05-01T03:36:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chockybickyman](https://avatars.discourse-cdn.com/v4/letter/c/7bcc69/32.png) [@chockybickyman](https://forum.kirupa.com/u/chockybickyman)\
**Post date:** [May 1, 2010, 3:36am UTC](https://forum.kirupa.com/t/image-loader-gallery/308833/1 "2010-05-01T03:36:52Z")

</div>

I have this piece of code to change images. I was trying to figure out how you could put a timer on the code, so if the image has been displayed for say 5 seconds it diverts to the next image automatically?

Also if it’s not to hard, when it has played to the end to divert to the 1st image.

preloader.swapDepths(999);  
arrows.swapDepths(998);  
depth\_sorter = 2;  
picture\_odd = 0;  
import mx.transitions.Tween;  
import mx.transitions.easing.\*;

function move\_stuff() {  
trace(picture\_odd);  
if(picture\_odd == 0){  
var tween\_handler:Tween = new Tween(picture\_0, “\_alpha”, Strong.easeOut, 0, 100, 2, true);  
tween\_handler.onMotionFinished = function(){  
//picture\_1.\_alpha = 100;  
}  
} else {  
var tween\_handler:Tween = new Tween(picture\_1, “\_alpha”, Strong.easeOut, 0, 100, 2, true);  
}  
}

function loadXML(loadedX) {  
if (loadedX) {  
xmlNode = this.firstChild;  
image = [];  
total = xmlNode.childNodes.length;  
for (i=0; i\<total; i++) {  
image\* = xmlNode.childNodes\*.childNodes[0].firstChild.nodeValue;  
}  
firstImage();  
} else {  
content = “file not loaded!”;  
}  
}

xmlData = new XML();  
xmlData.ignoreWhite = true;  
xmlData.onLoad = loadXML;  
xmlData.load(“images.xml”);  
p = 0;  
startClipX = 0;  
this.onEnterFrame = function() {  
if(picture\_odd ==0){  
filesize = picture\_0.holder.getBytesTotal();  
loadedX = picture\_0.holder.getBytesLoaded();  
} else{  
filesize = picture\_1.holder.getBytesTotal();  
loadedX = picture\_1.holder.getBytesLoaded();  
}  
if (loadedX != filesize && filesize \> 10) {  
loading = 1;  
if(loadedX \> 10){  
preloader.\_visible = true;  
} else{  
preloader.\_visible = false;  
}

```
	preloader.preload_bar._xscale = 100*loadedX/filesize;
} else if(loadedX &gt;= filesize && filesize &gt; 10) {
	if(loadedFile == 0){ 
	move_stuff();
	loadedFile = 1;
	}
	preloader._visible = false;
}

```

};

function load\_pic(){  
igm = p+1;   
loadedFile = 0;  
if (picture\_odd == 1){  
picture\_0.holder.loadMovie(image[p], 1);  
picture\_odd = 0;  
picture\_0.swapDepths(depth\_sorter);  
depth\_sorter +1;  
}else{  
picture\_1.holder.loadMovie(image[p], 1);  
picture\_odd = 1;  
picture\_1.swapDepths(depth\_sorter);  
depth\_sorter +1;  
}  
}

function nextImage() {  
prev\_img = 0;  
next\_img = 1;  
if (p\<(total-1)) {  
p++;  
if (loadedX == filesize) {  
load\_pic();  
picture\_num();  
}  
} else if (p==(total-1)) {  
p=0;  
if (loadedX == filesize) {  
load\_pic();  
picture\_num();  
}  
}  
}

function prevImage() {  
prev\_img = 1;  
next\_img = 0;  
if (p\<(total) && p\>0) {  
p–;  
if (loadedX == filesize) {  
load\_pic();  
picture\_num();  
}  
} else if (p==0) {  
p=total-1;  
if (loadedX == filesize) {  
load\_pic();  
picture\_num();  
}  
}  
}

function firstImage() {  
startClip = 1;  
if (loadedX == filesize) {  
load\_pic();  
picture\_num();  
}  
}

function picture\_num() {  
current\_pos = p+1;  
}
