PDA

View Full Version : Random image generator


unwrittendevin
03-05-2003, 05:49 PM
I have a question about creating a random image generator. I have 9 pictures I want to randomly appear on the stage, but I am having the hardest time with generating the code for it. I tried creating movie clips, using the Linkage option and exporting for Actionscript, but is this the right way to approach this problem? I've looked in a few books, and they tell me nothing except for how to generate random numbers, which works when I debug, but that's about it. Here's the code I've tried lately, just give me some feedback... Thanks

onClipEvent (enterFrame) {
ymca = new MovieClip();
ymca = 9;
directory = ymca;
loadMovieClip(directory add Math.ceil(Math.random(1)*ymca) . _level0);
randomPic = random(9)+1;
randomLoop = random(2)+1;
ymca.attachMovie("ymca"+randomPic);
ymca.start(0, randomLoop);
}

as you can tell, I haven't been actionscripting for long, it's mostly cut and pastes from books and tutes. Any help would be grateful!!!

Devin

Billy T
03-05-2003, 10:30 PM
ok so say you have 9 image mcs in your library with linkage names of image1, image2 etc

put a blank mc on the stage where you want the top left corner of the images to appear and add this code to it

onClipEvent (enterFrame) {
num = 9;
randomPic = random(num)+1;
this.attachMovie("image"+randomPic,1);
}