A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Display Random Images

  1. #1
    Member
    Join Date
    Apr 2003
    Location
    England
    Posts
    84

    Display Random Images

    Is there an easier way to display random images, for example I want it to display an image or two and then three or four second’s later change to another.

    I have over 100 images to display and don’t really want create each frame and place a new image on every 5 or so frame.

    There must be somewhere out there some action script that can do this, can anyone help I would very much appreciate it, and thanks in advances for your help.

    0rlando

  2. #2
    Lifesaver Lightwave Network's Avatar
    Join Date
    Sep 2002
    Location
    Denver, CO, USA
    Posts
    649
    Are you loading these images from an external JPG file or do you plan to embed them into your Flash movie?

    If you're using external JPGs (say in a folder called "images",) try this:

    code:

    myImageArray = ["image01.jpg", "image02.jpg", "image03.jpg", "image04.jpg"];

    _global.changeImage = function() {
    myImage = myImageArray[random(myImageArray.length)];
    someMovieClip.loadMovie("images/" + myImage);
    clearInterval(_root.changeImageIval);
    _root.changeImageIval = setInterval(changeImage, ((random(10)+1) * 1000) );
    }

    _root.changeImageIval = setInterval(changeImage, ((random(10)+1) * 1000) );
    //executes changeImage function after random milliseconds



    You would need a movie clip called "someMovieClip" to load the images into. In this case, the images need to be located in a folder in your app dir called "images".

    This should just about do it...I didn't test the code, but I'm pretty sure it works.

    Hope this helps!


    ... gimme just one more line of code to ease the pain.

    http://www.ln.tv
    http://www.davevillano.com
    http://www.premierloftsdenver.com
    http://www.backyard.cc -- coming soon!


  3. #3
    i am looking to do the same thing and i was wondering where you put that actionscript. do put it on the someMovieClip file, or do you go into the movie clip and put it in a frame? Thx.

  4. #4
    Lifesaver Lightwave Network's Avatar
    Join Date
    Sep 2002
    Location
    Denver, CO, USA
    Posts
    649
    You should be able to copy this AS and paste it into any frame of your Flash movie. You would be REQUIRED to have a Movie Clip with an instance name of "someMovieClip" located in the same level as the code. According to this code, you would also need to put your images in a folder called "images" within your Flash Movie's working folder.

    Hope this helps!


    ... gimme just one more line of code to ease the pain.

    http://www.ln.tv
    http://www.davevillano.com
    http://www.premierloftsdenver.com
    http://www.backyard.cc -- coming soon!


  5. #5
    Junior Member
    Join Date
    Apr 2010
    Posts
    1
    The code provided by Lightwave indeed works great in flash moviclip .
    THe images changes their order randomly well without any error .

    Want a help regarding this code :
    Is there any way to fade out the images .i.e one image fades out and other fades in ??
    I presume this can be achieved by alpha values , but dont know how .

    There is only single frame in my flash movie which plays this action . If I add more frames for a motion tween , the whole movie ( other layers as well ) gets affected and destroys the functioning .

    Can anyone help please ? Wud be highly appreciated .

    Regards ,
    Dr.Jatin Talwar
    M.S (Orthopaedics)

  6. #6
    Junior Member
    Join Date
    Jan 2014
    Posts
    1

    Help needed

    Hi,

    I'm trying to implement your code and i'm not having any success. I've created an empty movie called 'someMovieClip' and placed it on the stage. There is an empty key frame with your code (copied exactly from this message board). I also have a folder place inside the directory called 'images'. I exported the movie in the directory root but nothing happens when i open it?

    Any ideas what i'm doing wrong? many thanks in advance,

    Richard


    Quote Originally Posted by Lightwave Network View Post
    Are you loading these images from an external JPG file or do you plan to embed them into your Flash movie?

    If you're using external JPGs (say in a folder called "images",) try this:

    code:

    myImageArray = ["image01.jpg", "image02.jpg", "image03.jpg", "image04.jpg"];

    _global.changeImage = function() {
    myImage = myImageArray[random(myImageArray.length)];
    someMovieClip.loadMovie("images/" + myImage);
    clearInterval(_root.changeImageIval);
    _root.changeImageIval = setInterval(changeImage, ((random(10)+1) * 1000) );
    }

    _root.changeImageIval = setInterval(changeImage, ((random(10)+1) * 1000) );
    //executes changeImage function after random milliseconds



    You would need a movie clip called "someMovieClip" to load the images into. In this case, the images need to be located in a folder in your app dir called "images".

    This should just about do it...I didn't test the code, but I'm pretty sure it works.

    Hope this helps!

  7. #7
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    hi,

    That code above works as I tested it, it can take up to 10 seconds for the first event to happen, then it continues with gaps of between 1 - 10 seconds for the next image to occur, it could however pick the same number numerous times on the trot and seem like nothing is changing.

  8. #8
    Senior Member
    Join Date
    Nov 2012
    Posts
    106
    This may be an issue of Actionscript version.
    The above code is originally from 2004 and is AS2. Make sure your publish settings are AS2. If you are using Flash CC you will not be able to use this code without converting it to AS3.
    Quote Originally Posted by thomorw View Post
    Hi,

    I'm trying to implement your code and i'm not having any success. I've created an empty movie called 'someMovieClip' and placed it on the stage. There is an empty key frame with your code (copied exactly from this message board). I also have a folder place inside the directory called 'images'. I exported the movie in the directory root but nothing happens when i open it?

    Any ideas what i'm doing wrong? many thanks in advance,

    Richard

  9. #9
    Registered User
    Join Date
    Jan 2014
    Posts
    1
    You guys are really nice and nice post, shared with all. I really appreciate it and would like to say thanks to you that you share this post here with us.

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