-
Hello! Does nayone know a short script (Flash5) to make a new Array based on an existing one but with all items in random order? I've tried Array.Splice but I don't know much about programming.
Thanks a lot in advance! Jean-francois
-
If you are having trouble with the .splice, you can use a For loop to run through a cycle of numbers and use Math.random() to generate a random number inside a value of 0 and x (x being a number you specify). Then with that, store these numbers in in 2 variables (stored_numberA, stored_numberB) and assign the variables you want to be random to the stored variables.
I know its brief, but this will help. email helpmeben@yahoo.com and I will send you a example fla for you.
uberflash
-
Code:
myArray = new Array (1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
tempArray = new Array();
mylength = myArray.length - 1;
for (count = mylength ; count>=0; count-- ){
index = random(count);
tempArray[count] = myArray[index];
myArray[index] = myArray[count]
}
myArray = tempArray;
trace (myArray);
-
thanks!!
Thanks so much for the very fast reply!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|