2 Replies Latest reply on Nov 23, 2010 6:12 AM by westburyontrym

    Random SWFs

    westburyontrym

      Hello

       

      I have a website in which a random SWF is loaded each time the Home Page is refreshed.

       

      I have searched online, and have set up a file called "CJRandom.swf", which consists of the following:

       

      // Sets the number of Flash Movies in the random sequence
      // IMPORTANT: Set this number to how many Flash Movies you have
      var myMovieSequence = 30;

       

      // Creates the random number:
      var myRandomNumber = Math.floor(Math.random()*myMovieSequence)+1;

       

      // Creates the full Flash Movie name like: 1.swf
      var myMovieName = "CJFlash" + myRandomNumber + ".swf";

       

      // Loads the random Flash Movie:
      loadMovieNum(myMovieName, 0);

       

      There are 30 SWFs in total (i.e. CJFlash1.swf, CJFlash2.swf....CJFlash29.swf, CJFlash30.swf).

       

      When I run CJRandom as either an SWF within Flash or on the desktop, it works perfectly.  However, I have dropped the code into Dreamweaver into it's own div (RandomFlash).  The SWF file will not work either within Dreamweaver or if I upload it to the server - all I get is a blank space where the SWF should be.

       

      All the files are in the same folder, i.e. Images/FlashMovies/.

       

      I can't understand why this will not work within HTML and am tearing my hair out trying to get this to work on the website.

       

      I would appreciate any assistance.

        • 1. Re: Random SWFs
          Ned Murphy Adobe Community Professional & MVP

          When you place an swf in an html page, the html page becomes its basis of reference for anything it loads, so if your swfs are all in another folder than the html file, then you need to adjust the targeting inside CJRandom.swf to be as if it lives in the same directory as the html file.

           

          So if you use...  images/FlashMovies/CJRandom.swf

           

          to load the CJRandom.swf fle into the web page, then you need the CJRandom.swf file to also use the  images/FlashMovies/ to target the swfs it loads.

          • 2. Re: Random SWFs
            westburyontrym Level 1

            Ned

             

            Thanks for your help on this.  Apologies if I'm asking the obvious here.

             

            Here is my coding again:

             

            // Sets the number of Flash Movies in the random sequence
            // IMPORTANT: Set this number to how many Flash Movies you have
            var myMovieSequence = 30;

             

            // Creates the random number:
            var myRandomNumber = Math.floor(Math.random()*myMovieSequence)+1;

             

            // Creates the full Flash Movie name like: 1.swf
            var myMovieName = "/Images/FlashMovies/CJFlash" + myRandomNumber + ".swf";

             

            // Loads the random Flash Movie:
            loadMovieNum(myMovieName, 0);

             

            I have changed the third line to include the path (i.e. /Images/FlashMovies...), but this generates an error:

             

            Error opening URL 'file:///Images/FlashMovies/CJFlash4.swf' (or whatever the randomly generated file is).

             

            I would imagine this is because it is trying to read the file as /Images/FlashMovies/Images/FlashMovies/CJ....  What do I need to change to make this work?  Sorry if I seem a bit dense - I hate asking questions but want to get this knocked on the head.

             

            Thanks again.