hello, is there an easy way to have a one of 10 pictures randomly load when you visit the site ? ive seen this on many pages and im wondering how its done. here is an example http://www.tammyeckenswiller.com thanks, boomtown
could you choose a random #, and add that to the filename, so its now pic1.jpg
lets say I want it to load into a specific xy coordinate, would I create a mc in the desired position and add some code like this var randomImage:Number = random(7); loadMovie('images/image'+randomImage+'.jpg'); thanks
the best way to create a random number is to use the 'MOD' symbol in conjuction with Random. Since Math.Random will always create a number between 0-1 (i.e. ..01483892929495), you need to manipulate it first: var rand_pic:Number = (Math.round((Math.random())*1000)%2); **multiply by 1000 to get a positive number, then use round to create a whole number. Then, whatever you '%' by will return an integer representing the 'remainder'... EX. 14%3 = 2; or 999%10 = 9; I recommend using an array to store your paths to the images and use the random integer to access the array.: myArray = ('one.jpg','two.jpg','three.jpg'); // randNum = (Math.round((Math.random())*1000)%9); //**by using '%9', you will get an integer between 0 and 9 (remember an Array begins with [0] randomPic = myArray [randNum ;] // myMovieClip.loadMovie(randomPic );
Don't see what you're looking for? Try a search.
|