10 Replies Latest reply on Sep 27, 2008 10:53 PM by phi nupe

    Load Random SWF

    necie
      I want to load a random swf (I have five) each time a user goes to the site or hits refresh. I've researched this forum for an "easy" solution as well as buying an ActionScript book. I'm am in no way very savy with this subject. Is there an easy code to do what I need or will I have to immerse myself in understanding arrays, etc.

      If someone can't provide any code could you please provide a clear basic path of the steps I have to go through so I can research each step one at a time to get the results I want.

      Thanks in advance.
        • 1. Load Random SWF
          Damon Edwards Level 3
          :
          • 2. Re: Load Random SWF
            Ben Danis Level 1
            this is a solution if you don't wan't to deal with Javascript or whatever server side script you are using.

            have a holder on your flash site
            call it index.swf.
            this flash movie will then load a random movie within itself
            write this code in the root
            var aFileNames = ["file1", "file2", "etc"]; // a list of your movie names
            createEmptyMovieClip("mContent",0);
            mContent.loadMovie("RelPathToTheFile/"+ aFileNames[random(aFileNames.length)] + ".swf"];

            place this in your html page and it should work
            • 3. Re: Load Random SWF
              necie Level 1
              dzedward,
              Thanks for taking the time. Do I need to change anything in the code other than the .swf names? I pasted the code onto frame 1 and saved the .fla in the same directory as my .swf files I want to randomly load. when I go to test the movie it's not working. Am I doing something wrong?
              • 4. Re: Load Random SWF
                Damon Edwards Level 3
                you need an empty movie clip on stage with instance name of, yourMC
                • 5. Re: Load Random SWF
                  necie Level 1
                  Just to make sure I have this right. On frame 1 I pasted the script you provided into the actions panel (I also added a stop() action to start off). I created a new MC and named it mc_empty, put an instance of it on stage and named the instance "yourMC". In the same directory as my .fla file (and .swf created when testing) I have four files, 1.swf, 2.swf, 3.swf, and 4.swf. When I go and test the movie nothing loads. What am I missing? If you want to check the files out, I have posted them here: www.mikeyhaynes.com\RandomLoadFiles_debug.zip

                  They are all very small files used just for testing. Once again thanks with this.

                  Mike
                  • 6. Re: Load Random SWF
                    necie Level 1
                    Just to make sure I have this right. On frame 1 I pasted the script you provided into the actions panel (I also added a stop() action to start off). I created a new MC and named it mc_empty, put an instance of it on stage and named the instance "yourMC". In the same directory as my .fla file (and .swf created when testing) I have four files, 1.swf, 2.swf, 3.swf, and 4.swf. When I go and test the movie nothing loads. What am I missing? If you want to check the files out, I have posted them here: www.mikeyhaynes.com\RandomLoadFiles_debug.zip

                    They are all very small files used just for testing. Once again thanks with this.

                    Mike
                    • 7. Re: Load Random SWF
                      Damon Edwards Level 3
                      yourMC needs to be yourMc, sorry bout the lazy fingers hehe
                      • 8. Re: Load Random SWF
                        necie Level 1
                        After a week of banging my head against my desk.... RELIEF AT LAST!!! That did the trick!!!!! Thanks so much for you help and time.
                        • 9. Re: Load Random SWF
                          Damon Edwards Level 3
                          you're welcome.
                          • 10. Re: Load Random SWF
                            phi nupe Level 1
                            I also want to say "thanks" for the solution. It works!