Randomization Question

Hi
I tried out the tutorial on random colors in Flash and thought it was really cool. I was wondering if there is a way to use images instead of colors, for example images that have been imported to the library? Also is it possible to move objects randomly? If anyone knows please let me know.
Thanks so much
nom44

There a tutorial on random movement! But the random picture one! That one needs attachMovieClip(); I think david know that one better than… or anyone!

<b>A simple random pic chooser - this will call in a randomly chosen swf (containing a pic) into the main movie.</b>

<b>Ingredients:</b>

6 swfs each containing an image (i.e. open a new movie import a pic and export the swf). Label them consistently e.g.
pic11.swf
pic12.swf
pic13.swf

pic16.swf

<b>Method:</b>

Call the swf in one at a time using loadMovieNum()

For starters try:

loadMovieNum (“pic11.swf”, 0);

This should load the first pic into the main timeline - if it doesn’t, check all your picture swfs are in the same directory as the main movie

<b>If that works, then try:</b>

randomPic=“pic”.concat(Math.floor(Math.random()*6)+11, “.swf”);
loadMovieNum (randomPic, 0);

If we break down the randomPic=“pic”… line you can see it uses the following methods

“x”.concat(“y”,“z”);
This joins the three strings together eg pic+11+.swf= pic11.swf

Math.floor();
This takes the lowest round number corresponding to any given number e.g. 6.1=6, 6.5=6, 158.4=158, etc.

Math.random();
This chooses a random number between 0 and 1

Math.floor(Math.random()*6
This chooses the random number 0,1,2,3,4 or 5. By contrast,
Math.ceil(Math.random()*6 will choose either 1,2,3,4,5 or 6 because it takes the highest corresponding integer.

+11
converts 0,1,2, etc into 11,12,13,etc.

Obviously you can call the imported swfs anything you like and you can have as many as you like, changing randomPic accordingly.

So why number them from 11 instead of from 1? Because it’s not unlikely that you’ll add more than 10 random pics and if you want to reference them with AS using say _name or _url for example then it’s hand to know that they’ll all take the generic form picXX.swf where XX is a 2 digit integer.

<b>If you don’t like the concat method above you could always try:</b>

picArray = new Array(“serval.swf”, “cougar.swf”, “ocelot.swf”, “jaguar.swf”);
randomPic=picArray[Math.floor(Math.random()*picArray.length)];