Using a variable in the random() function

I’m loading jpegs in to my page externally using the following function:

loadMovie(“image”+random(24)+".jpg", “_root.container”);

That works great, the thing is however, I want the people that will be editing the site to be able to just type the number into a text file and then have that number be used by the random function. I’m having problems getting this to work and I’m not sure if random() lets you use a variable.

Here’s what I’ve tried with no success:

In the random image layer which resides on the main timeline–

loadMovie(“image”+random(_global.pictotal)+".jpg", “_root.container”);

In the actions layer which also resides on the main timeline here is my variable declaration–

_global.pictotal = this.pictotal;

In my text file, here’s the line that gives it the value 24-

&pictotal=24&

Is this just not possible with random() and if that is true, is there another way to randomly load jpegs using a variable to define how many there are in the directory so no blanks show up.

[AS]loadText = new loadVars();
loadText.load(“pictures.txt”);
loadText.onLoad = function(OK) {
if (OK) {
var whichPic = Math.floor(Math.random()*this.pictotal)+1;
container.loadMovie(“image”+whichPic+".jpg");
}
};[/AS]And inside your pictures.txt file:

pictotal=24&

Hey thanks, that does the job. I was wondering if you could briefly describe what is going on in this line:

*Math.floor(Math.random()this.pictotal)+1;

I’d just like to know what is going on. Like why you didn’t need to stick any numbers in the random() function there and what is the asterisk for. Thanks again for the help.

the asterisk means multiply. You can learn more about the random deal here:
http://www.kirupaforum.com/forums/showthread.php?s=&postid=81565#post81565

Ok that post you referred to cleared everything up. Thanks alot.

welcome :slight_smile:

You’re welcome :slight_smile: