Skip to main content
Inspiring
February 7, 2007
Answered

shuffle XML nodes

  • February 7, 2007
  • 2 replies
  • 648 views
During the onLoad of an XML file, I would like Flash to do a random shuffle of the XML nodes.

Each node contains a song title and mp3 URL. Need to shuffle the order of the nodes.

Any ideas on how to code that?

Thanks.
-CK
This topic has been closed for replies.
Correct answer Jan-Paul_K_
heres a shuffle function for the array object:

Array.prototype.shuffle=function(){
for(i=0;i<this.length;i++){
var tmp=this ;
var randomNum=random(this.length);
this
=this[randomNum];
this[randomNum]=tmp;
}
}

2 replies

Jan-Paul_K_Correct answer
Inspiring
February 7, 2007
heres a shuffle function for the array object:

Array.prototype.shuffle=function(){
for(i=0;i<this.length;i++){
var tmp=this ;
var randomNum=random(this.length);
this
=this[randomNum];
this[randomNum]=tmp;
}
}
Inspiring
February 7, 2007
there is no radnomizer function for xml nodes, I suggest you store the relevant nodes into an array and then use Math.random() to access a random index of that array.