Page 1 of 1

Randomizing contents of a list box

Posted: Thu Oct 08, 2015 11:07 pm
by jsaps
I have been working on a making a media player for a project that displays its songs in a list box. These "songs" are classes which contain attributes that have their name, length, directory path, artist etc, however only their names are displayed as elements in the list box. What I want to do is make a button that operates essentially the same as a shuffle button would, and randomize the order of the contents of the list box. In my attempts thus far I have created a button which randomly selects and plays a song out of the list box by randomly generating a list index, but cannot for the life of me figure out how to actually reorder the list box itself.

Any help with this would be much appreciated - and apologies if this post is in the wrong place or anything of that nature, I am very new to Jade and these forums :)

Re: Randomizing contents of a list box

Posted: Fri Oct 09, 2015 1:26 am
by ghosttie
Copy the collection of all songs into a temporary array and create an empty array of song objects. Loop while the array of all songs is not empty, and each time randomly pick a song from the array, remove it from that array and add it to the second array. Then use that array in your listbox.

Re: Randomizing contents of a list box

Posted: Tue Oct 13, 2015 9:23 am
by JohnP
What ghostie said, and also ensure your listbox has the "sorted" attribute set to false.