Randomizing contents of a list box

Forums for specific tips, techniques and example code
jsaps
Posts: 1
Joined: Thu Oct 08, 2015 10:51 pm

Randomizing contents of a list box

Postby jsaps » Thu Oct 08, 2015 11:07 pm

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 :)

User avatar
ghosttie
Posts: 181
Joined: Sat Aug 15, 2009 1:25 am
Location: Atlanta, GA, USA
Contact:

Re: Randomizing contents of a list box

Postby ghosttie » Fri Oct 09, 2015 1:26 am

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.
I have a catapult. Give me all the money or I will fling an enormous rock at your head.

JohnP
Posts: 73
Joined: Mon Sep 28, 2009 8:41 am
Location: Christchurch

Re: Randomizing contents of a list box

Postby JohnP » Tue Oct 13, 2015 9:23 am

What ghostie said, and also ensure your listbox has the "sorted" attribute set to false.


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 16 guests

cron