# Randomizing an XML Array

**URL:** <https://forum.kirupa.com/t/randomizing-an-xml-array/79777>\
**Category:** flash\
**Created:** [February 16, 2005, 11:31pm UTC](https://forum.kirupa.com/t/randomizing-an-xml-array/79777 "2005-02-16T23:31:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![misterpatrick](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@misterpatrick](https://forum.kirupa.com/u/misterpatrick)\
**Post date:** [February 16, 2005, 11:31pm UTC](https://forum.kirupa.com/t/randomizing-an-xml-array/79777/1 "2005-02-16T23:31:39Z")

</div>

Hello all,

I’m having problems with the script below. Basically, it loads and parses an external XML file. I have it set to just step through the file but I’d like it to randomly display the images referenced by the XML. The script works like this, but I can’t seem to figure out how to get the XMl into an array and then have the function read it correctly. It seems to me that the call:

picture.loadMovie(image[p], 1);

with p being changed somehow to a call to myArray should work, but it doesn’t. What am I doing wrong?

////this creates the load XML function and counts the children to an array  
function loadXML(loaded) {  
if (loaded) {  
xmlNode = this.firstChild;  
image = [];  
description = [];  
total = xmlNode.childNodes.length;  
for (i=0; i\<total; i++) {  
image\* = xmlNode.childNodes\*.childNodes[0].firstChild.nodeValue;  
description\* = xmlNode.childNodes\*.childNodes[1].firstChild.nodeValue;  
}  
firstImage();  
} else {  
content = “file not loaded!”;  
}  
}

////basic XML data stuff  
xmlData = new XML();  
xmlData.ignoreWhite = true;  
xmlData.onLoad = loadXML;  
xmlData.load(“images.xml”);

//////////////////file loader  
p = 0;  
this.onEnterFrame = function() {  
filesize = picture.getBytesTotal();  
loaded = picture.getBytesLoaded();  
preloader.\_visible = true;  
if (loaded != filesize) {  
preloader.preload\_bar.\_xscale = 100\*loaded/filesize;  
} else {  
preloader.\_visible = false;  
if (picture.\_alpha\<100) {  
picture.\_alpha += 10;  
}  
}  
};

function firstImage() {  
if (loaded == filesize) {  
picture.\_alpha = 0;  
picture.loadMovie(image[0], 1);  
desc\_txt.text = description[0];  
picture\_num();  
}  
}

function autoImage() {  
if (p\<(total-1)) {  
p++;  
if (loaded == filesize) {  
picture.\_alpha = 0;  
picture.loadMovie(image[p], 1);  
desc\_txt.text = description[p];  
picture\_num();  
}  
}  
}  
setInterval(autoImage, 10000);

/////Array shuffle  
Array.prototype.Shuffle = function() {  
for (var j=this.length-1; j\>0; j–) {  
var pick = random(j);  
var tmp = this[pick];  
this[pick] = this[j];  
this[j] = tmp;  
}  
};

///so the XML needs to loaded into the array somehow. Here’s the array with a bunch of numbers instead of the XML info.  
myArray=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];  
myArray.Shuffle();
