PDA

View Full Version : slideshow application help


tracisummers
08-08-2009, 02:56 AM
Hello,

I'm having a bit of a problem with an slideshow application and was hoping someone could help.

What I want to do is randomly select a file from an array. If the random array location also contains an array, pick a random location in this array and so on..
It will keep going until if finds a location that isn't an array and meets some other conditions.

I've drawn that out from what I'm actually doing but the logic is the same, although I can't figure that logic out for the life of me.

Any help appreciated.

ASWC
08-08-2009, 04:44 PM
You could do something like that with a recursive function:


var array:Array = new Array();
array.push("1");
array.push("2");
array.push("2");
array.push(new Array("3","4","5"));
array.push(new Array("6","7","8"));
array.push(new Array("9","10","11"));
array.push(new Array("12","13",new Array("14","15","16")));

trace(getAString(array));

function getAString(array:Array):String{
var Results:String;
var index:int = Math.floor(Math.random()*array.length);
if(array[index] is Array){
Results = getAString(array[index]);
}
else{
Results = array[index];
}
return Results;
}

tracisummers
08-08-2009, 06:03 PM
Thanks ASWC. All seems rather obvious now :o