Groups | Blog | Home
all groups > flash actionscript > february 2005 >

flash actionscript : randomize


Dave Mennenoh
2/12/2005 6:01:38 PM
If you look at the source of the site you referenced you'd see the random
part is coming from main.htm.
If you go there: http://www.tammyeckenswiller.com/main.htm
You can view source again and see the javascript being used to randomize the
images. Nothing fancy.


--
Dave
http://www.blurredistinction.com/director
Team Macromedia Volunteer
http://www.macromedia.com/go/team

boomtownUSA
2/12/2005 11:36:20 PM
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
dedtr9
2/13/2005 12:07:47 AM
could you choose a random #, and add that to the filename, so its now pic1.jpg
boomtownUSA
2/13/2005 12:23:05 AM
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
silverfishmedia
2/13/2005 1:35:03 AM
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 );
AddThis Social Bookmark Button