A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Random numbers?

  1. #1
    Junior Member
    Join Date
    Oct 2004
    Posts
    5

    Random numbers?

    How do I make a random number that corresponds to the frame I want to go to?(I'm using Flash MX)

  2. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Let's say you want to choose between frames 10,37,47 and 100.

    code:

    choices = [10,37,47,100];
    frameNumber = choices [ random(choices .length) ];
    gotoAndPlay(frameNumber);



    For flexibility, you can also (and probably should) do it with frame labels.

    code:

    choices = ['john','paul','george','ringo'];
    frameNumber = choices [ random(choices .length) ];
    gotoAndPlay(frameNumber);



    If the frames are sequential, say 1-10, you can do it this way:

    code:

    gotoAndPlay( random(10)+1 );



    Finally, if anyone posts code to this thread suggesting the use of Math.round() in conjunction with Math.random(), they are seriously deluded. I've posted numerous times about this subject in prior threads. Look it up.
    Last edited by jbum; 10-01-2004 at 05:44 PM.

  3. #3
    Junior Member
    Join Date
    Oct 2004
    Posts
    5
    When I publish it says there's an error and that statement must appear in on handler. What does that mean?
    Nevermind I got it.
    Last edited by Pyte; 10-01-2004 at 06:35 PM.

  4. #4
    Junior Member
    Join Date
    Oct 2006
    Posts
    1
    I want to do somethng similar to this and have become a bit stuck. What I want to do is have 10 or so images that can be used on a homepage randomly. Using the previous methods i have managed to get the .swf to randomly scroll through the images before choosing one. I dont want it to scroll though, I want i to choose one straight away. Is there a way of doing this?

    To see what i have done so far visit www.suggymoto.com/main.html

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center