A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Randomized Pictures...

  1. #1
    Is there a way to place a radomized picture into a flash movie?? For example, you had 5 seperate images, all sized the same, and were loaded into the movie as a background, then each time the visitor came to the site, there was a potential of 5 different background he or she might see...

    Any thoughts?? Anyone...Beuhler??

  2. #2
    Senior Member
    Join Date
    Jun 2000
    You put each of the 5 picures in a different frame, with a blank frame befor them all.
    Then you make an invisible movieclip with 3 frames.


    bg = random(6);

    if (bg >= 1) {
    gotoAndPlay (2);
    } else {
    _root.gotoAndPlay (bg);
    gotoAndStop (1);

    What this does, is generates a random number between 2 and 6, and tells the main timeline, to go to that frame.

    Now, in the blank frame I mentioned befor, you simply put:
    stop ();
    _root.randomthing.gotoAndPlay (2);

    good luck!

    Oh and, you may need to put:
    _root.gotoAndPlay (Number(bg));

    instead of:
    _root.gotoAndPlay (bg);

    I think, but I cant remember if it is gotoAnd* that doesnt like having a variable in its arguments..

  3. #3
    Thanks soooo much for the help...for some reason though, it the movie doesn't get past the first frame...

    As for the invisible movie clip, I put that on a second layer...should I just have that on the first frame, or on each of the frames that contain a picture?? I would assume that it needed to be on the first frame so it could generate the random nubmer...

    Thanks for you input!!

  4. #4
    Join Date
    Dec 2000
    On frame 3 I think it should be
    if (bg <= 1) {
    gotoAndPlay (2);

  5. #5
    you can also create one movieclip, create 6 keyframes. leave the first one blank, now in each frame from 2 to 6, insert one of the backgrounds.

    then, add this code on the empty frame 1:

    frame = random(8)+2;
    gotoAndStop (frame);

  6. #6
    Senior Member
    Join Date
    Jun 2000
    Robson, ugh I can never use those symbols..
    It has to be 'less than,' which ever that is.

    random(8)+2; is a good idea, but it think its random(4)+2..?
    [Edited by cym on 04-05-2001 at 10:34 AM]

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