img rotation script
- Started
- Last post
- 5 Responses
- jox
I have six images in a row on a webseit.
I have a folder with 20 pics.
How do I rotate them so each and everyone is shown an equal amount of time, but never twice in the same session?
- acescence0
if you're going from page to page, you need something that is going to persist across a user's visit, so either a cookie on the client, or storing a session on the server
- jox0
Ah, no actually it's really simple, all just on one page.
- acescence0
put all the images into an array and step through them one by one until you reach the end
- Monokai0
And to randomize that array, use this function:
public static function randomize(array:Array):Array {
if (array.length < 2) return array;
var i:Number = array.length;
while (--i) {
var j:Number = Math.floor(Math.random() * (i + 1));
var tmp1:Object = array[i];
var tmp2:Object = array[j];
array[i] = tmp2;
array[j] = tmp1;
}
return array;
}
- jox0
You rock, seriously! I owe you one.