5 Replies Latest reply on Jun 17, 2009 8:38 AM by RossRitchey

    Random Image loader

    heazle Level 1

      I have a series of 10 jpg's. I want a a different image (1 of the 10) to load up in the home page every time someone starts up the web page what is the best way of doing this.  Also what is the best format to use for an image in flash, png., pdf, or some other?

        • 1. Re: Random Image loader
          RossRitchey Level 4

          I would drop the filenames into an array (or externalize it with an XML document - and drop the names into an array on load)


          Then, pick a random number, based on the length of the array and load the image at that location in the array.




          var files:Array = new Array();












          var rand:Number = Math.floor(Math.random()*files.length);




          or something similar should do the trick (where myLoader is a Loader component)

          • 2. Re: Random Image loader
            heazle Level 1

            do theese images need to be stored within the "randimages" flash file or are they stored in a container folder that Flas looks for, like loading an external swf file.

            • 3. Re: Random Image loader
              RossRitchey Level 4

              Typically the best way is to keep them external (in a folder next to the Flash file).  That is best for updateability (if you ever want to add/change images, you can do it without changing the SWF).


              You can, however, put them in the library as well.

              • 4. Re: Random Image loader
                heazle Level 1

                thank you for your help so far, I am having a problem doing this correctly

                I have created a new file called randimages.fla and I created a folder with the files (1-10.jpg) located in it (outside of the randimages.fla document) I copied the script that you sent me into the fist blank frame with a stop(); action after it, the images do not load up.

                • 5. Re: Random Image loader
                  RossRitchey Level 4

                  The code I wrote was not meant to be used directly, but instead to give you an idea of the steps.


                  I assume you changed the names in the array to direct to your files, rather than an example?  This includes the folder they are in.


                  Did you place a Loader component on the stage and give it an instance name "myLoader"?