AS3: Need help with random photo switcher

Hi everyone…I’m still very much a newbie when it comes to AS3.

I need to create an external image scroller. That’s simple enough, but these images are of people of different ethnics groups, roughly divided into four categories.

So, the pictures need to be randomized two-dimensionally. The first random factor is which of the four groups to choose from. The second random factor is which image in that group to display.

That way, no ethnic group is favored over another.

I’ve gotten fairly far…when I test my Flash file and click the Start button, you’ll see the first random image. Wait a few seconds, and the second will appear. All well and good…but the logic for how to randomize and automatically display all 15 images eludes me, despite days of research.

Can anyone point me in the right direction? I tried to upload the test files but they’re too big, so the code is below.


[FONT=Courier New][COLOR=green]import flash.utils.*;

/* An array of four different groups of photos */

var myPhotos:Array = new Array();

myPhotos[0] = [“01.jpg”,“02.jpg”,“03.jpg”,“04.jpg”,“05.jpg”];

myPhotos[1] = [“06.jpg”,“07.jpg”,“08.jpg”,“09.jpg”];

myPhotos[2] = [“10.jpg”,“11.jpg”,“12.jpg”];

myPhotos[3] = [“13.jpg”,“14.jpg”,“15.jpg”];

/* Four functions that generate a random index from each array */

var max1:Number = myPhotos[0].length;
var min1:Number = 0;
var randomPhoto0:Number = Math.round(Math.random() * (max1 - min1) + min1);

var max2:Number = myPhotos[1].length;
var min2:Number = 0;
var randomPhoto1:Number = Math.round(Math.random() * (max2 - min2) + min2);

var max3:Number = myPhotos[2].length;
var min3:Number = 0;
var randomPhoto2:Number = Math.round(Math.random() * (max3 - min3) + min3);

var max4:Number = myPhotos[3].length;
var min4:Number = 0;
var randomPhoto3:Number = Math.round(Math.random() * (max4 - min4) + min4);

// Here’s where it gets dicey. I want a function that loads a random image from any array.

// The next image must also be random, AND from a different array group.

// And so on…the intent is maintain the diversity of the pictures, so that

// no ethnic group gets precedence over another.

function switchPhotos(event:MouseEvent):void
var req:URLRequest = new URLRequest(myPhotos[0][randomPhoto0]);
var loader:Loader = new Loader();

function photoTwo(event:TimerEvent):void
var req:URLRequest = new URLRequest(myPhotos[1][randomPhoto1]);
var loader:Loader = new Loader();

var myTimer:Timer = new Timer(5000);
myTimer.addEventListener(“timer”, photoTwo);

// This button is only for testing. The actual movie should play and rotate the images automagically.

start_btn.addEventListener(MouseEvent.CLICK, switchPhotos);[/COLOR][/FONT]