# Load images randomly

**URL:** <https://forum.kirupa.com/t/load-images-randomly/225268>\
**Category:** Uncategorized\
**Created:** [May 10, 2007, 6:51am UTC](https://forum.kirupa.com/t/load-images-randomly/225268 "2007-05-10T06:51:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nickycdk](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nickycdk/32/2533_2.png) [@nickycdk](https://forum.kirupa.com/u/nickycdk)\
**Post date:** [May 10, 2007, 6:51am UTC](https://forum.kirupa.com/t/load-images-randomly/225268/1 "2007-05-10T06:51:45Z")

</div>

I got this XML slideshow.

My xml looks like this:  
\<?xml version=“1.0” encoding=“utf-8” standalone=“yes”?\>

\<images\>  
\<pic\>  
\<image1\>billeder/1.jpg\</image1\>  
\<image2\>billeder/2.jpg\</image2\>  
\<image3\>billeder/3.jpg\</image3\>  
\<image4\>billeder/4.jpg\</image4\>  
\</pic\>  
\<pic\>  
\<image1\>billeder/5.jpg\</image1\>  
\<image2\>billeder/6.jpg\</image2\>  
\<image3\>billeder/7.jpg\</image3\>  
\<image4\>billeder/8.jpg\</image4\>  
\</pic\>  
\<pic\>  
\<image1\>billeder/1.jpg\</image1\>  
\<image2\>billeder/2.jpg\</image2\>  
\<image3\>billeder/3.jpg\</image3\>  
\<image4\>billeder/4.jpg\</image4\>  
\</pic\>  
\</images\>

Right nok my script gets the four images that are in \<pic\> and fade’s them ind at the same time…

And after x seconds it does it all over again.

What i would like it to do is after the four images are faded in, then it only should change one image at a time, which should be randomly…

My script at the MainTimeline in AS layer:

\_root.p = 0;

function loadXML(loaded) {  
//If XML is loaded  
if (loaded) {  
var xmlNode = this.firstChild;  
image1 = [];  
image2 = [];  
image3 = [];  
image4 = [];  
\_root.total = xmlNode.childNodes.length;  
for (i=0; i\<total; i++) {  
image1\* += xmlNode.childNodes\*.childNodes[0].firstChild.nodeValue;  
image2\* += xmlNode.childNodes\*.childNodes[1].firstChild.nodeValue;  
image3\* += xmlNode.childNodes\*.childNodes[2].firstChild.nodeValue;  
image4\* += xmlNode.childNodes\*.childNodes[3].firstChild.nodeValue;  
}  
upDatePic();  
} else {  
content = “file not loaded!”;  
}  
}  
xmlData = new XML();  
xmlData.ignoreWhite = true;  
xmlData.onLoad = loadXML;

[//xmlData.load](https://xmlData.load)("/site/utils/toppics.asp?doc\_id="+doc\_id);  
xmlData.load(“images.xml”);

//Preload  
this.onEnterFrame = function() {  
filesize = picture1.getBytesTotal();  
loaded = picture1.getBytesLoaded();  
preloader.\_visible = true;  
if (loaded != filesize) {  
preloader.preload\_bar.\_xscale = 100\*loaded/filesize;  
} else {

preloader.\_visible = false;  
//If pictures alpha is smaller then 100, then fade i up  
if (picture1.\_alpha \< 100) {  
picture1.\_alpha += 3; //Hastighed, jo størrere, jo hurtige vil billedet bliver vist  
}  
if (picture2.\_alpha \< 100) {  
picture2.\_alpha += 3; //Hastighed, jo størrere, jo hurtige vil billedet bliver vist  
}  
if (picture3.\_alpha \< 100) {  
picture3.\_alpha += 3; //Hastighed, jo størrere, jo hurtige vil billedet bliver vist  
}  
if (picture4.\_alpha \< 100) {  
picture4.\_alpha += 3; //Hastighed, jo størrere, jo hurtige vil billedet bliver vist  
}  
}  
}

//Updates picture  
function upDatePic (){

if (loaded == filesize) {  
picture1.\_alpha = 0;  
picture1.loadMovie(image1[p],1);

picture2.\_alpha = 0;  
picture2.loadMovie(image2[p],2);

picture3.\_alpha = 0;  
picture3.loadMovie(image3[p],3);

picture4.\_alpha = 0;  
picture4.loadMovie(image4[p],4);

picture\_num();

}  
}

function picture\_num() {  
current\_pos = p+1;  
pos\_txt = current\_pos+" / "+total;  
}

* * *

MovieClip Timer (AS Layer)

if (\_root.p \< (\_root.total-1)) {  
\_root.p = \_root.p += 1;  
} else {  
\_root.p = 0;  
}  
\_root.upDatePic();

Hope you can help, if you dont quite understand the question, the script can be downloaded
