3 Replies Latest reply on Apr 12, 2011 11:40 AM by Ned Murphy

    Random Movieclip


      Hey there, for my A2 coursework, I'm making a tutorial, and I decided to add four movieclips which play randomly.


      I've got the code (which does work to some extent), but it only wants to play the last three movieclips, but not the first.


      Below is the code I am using:

      function(){return A.apply(null,[this].concat($A(arguments)))}

      trans = 0;

      trans = (Math.floor(Math.random()*4))+1;

      if(trans==1) gotoAndPlay("tr1");
      if(trans==2) gotoAndPlay("tr2");
      if(trans==3) gotoAndPlay("tr3");
      if(trans==4) gotoAndPlay("tr4");


      Is there any way I can get the first movieclip to play, while keeping the random function?

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

          That random code line will correctly choose a value of 1 thru 4 for trans, so that is not the problem.  You just might need to wait to see the first coming up or you don't have a frame labeled "tr1".  Just put a trace(trans); after the value gets calculated and you should see it appear at some point.


          You can prove that random number generating line results in 1 thru 4 by using the following as a test...


          trans = 0;

          this.onEnterFrame = function(){
               trans = (Math.floor(Math.random()*4))+1;

          1 person found this helpful
          • 2. Re: Random Movieclip
            aoneill321 Level 1

            Thanks man. By using trace, I found that whenever it got 1 in the RNG, it decided to play the 2nd movieclip anyway, due to the fact I didn't put a stop function on (so I changed the first movie clip play bit to gotoAndStop();). Once again, thanks

            • 3. Re: Random Movieclip
              Ned Murphy Adobe Community Professional & MVP

              You're welcome