ActionScript Code:
var theXML:XML = new XML();
theXML.ignoreWhite = true;
titlesArray = new Array();
idsArray = new Array();
discsArray = new Array();
imagesArray = new Array();
function findRandomNumBetween(Low, High)
{
return 1 + Math.floor(Math.random() * ((High - Low))) + (Low);
}
function find5RandomItems()
{
trace(idsArray[0]);
trace(idsArray[(idsArray.length - 1)]);
item1 = findRandomNumBetween(idsArray[0], idsArray[(idsArray.length - 1)]);
item2 = findRandomNumBetween(idsArray[0], idsArray[idsArray.length - 2]);
if (item2 >= item1)
{
item2 += 1;
}
item3 = findRandomNumBetween(idsArray[0], idsArray[idsArray.length - 3]);
if (item3 == item2)
{
item3 += 1;
}
if (item3 == item1)
{
item3 += 1;
}
item4 = findRandomNumBetween(idsArray[0], idsArray[idsArray.length - 4]);
if (item4 == item3)
{
item4 += 1;
}
if (item4 == item2)
{
item4 += 1;
}
if (item4 == item1)
{
item4 += 1;
}
item5 = findRandomNumBetween(idsArray[0], idsArray[idsArray.length - 5]);
if (item5 == item4)
{
item5 += 1;
}
if (item5 == item3)
{
item5 += 1;
}
if (item5 == item2)
{
item5 += 1;
}
if (item5 == item1)
{
item5 += 1;
}
item6 = findRandomNumBetween(idsArray[0], idsArray[idsArray.length - 6]);
if (item6 == item5)
{
item6 += 1;
}
if (item6 == item4)
{
item6 += 1;
}
if (item6 == item3)
{
item6 += 1;
}
if (item6 == item2)
{
item6 += 1;
}
if (item6 == item1)
{
item6 += 1;
}
trace(item1);
trace(item2);
trace(item3);
trace(item4);
trace(item5);
trace(item6);
}
theXML.onLoad = function()
{
for (i = 0; i < theXML.childNodes.length - 1; i++)
{
titlesArray.push(theXML.childNodes[i].childNodes[0].childNodes);
idsArray.push(theXML.childNodes[i].childNodes[1].childNodes);
discsArray.push(theXML.childNodes[i].childNodes[2].childNodes);
imagesArray.push(theXML.childNodes[i].childNodes[3].childNodes);
}
find5RandomItems();
};
theXML.load("xmlinfo.xml");
I'm having a problem. I have information coming in from an XML page. One of the childnodes is an ID. The numbers of the IDs go from 29 to 40. I'm trying to have 6 numbers randomly grabbed from the list, so I made a function to find a random number between a given "Low" and "High" numbers, then another to continuously add 1 if it's already one of the other numbers(I'm pretty sure the method of that part, I could have taken a short cut.)
Where it says to trace the two numbers near the top of the find5RandomNumbers function, they trace 29 and 40. But near the bottom where it's told to trace all 6 items, they come back as "NaN."
Thank you in advance to anyone who is willing to help.. I've been pulling my hair out over this, and I'm sure it's something really simple... x_x
Here's an example of the XML if you need it; it goes up till ID is 40.
Code:
<products>
<name>Bananas</name>
<id>29</id>
<description><p>Monkeys food.</p></description>
<imageURL>monkeyWithBanana.jpg</imageURL>
</products>
<products>
<name>Apples</name>
<id>30</id>
<description><p>Great for throwing at people</p></description>
<imageURL>appleMotorcycleAccident.jpg</imageURL>
</products>
........