7 Replies Latest reply on Dec 11, 2009 3:38 PM by kglad

    How do I randomly start a list of swfs?

    jare23

       

      I'm looking for a way to randomly start an ordered list of SWF's.

       

      Well, that's not all...

      I have my main SWF calling up external SWF's. I have 2 groups of external SWF's

      From my main SWF Actionscript, I want to randomly play one SWF in Group A and continue cycling through Group A (in order) until it is finished.

      Then I want to randomly start playing one SWF from Group B and continue cycling through that list (in order) until the Group B is cycled through.

      Then repeat Group A (random start, but staying in order), etc.

       

      Does this make sense?? I realize it's a challenge-

       

      My current ActionScript works for Group A to randomly select and play in order, I need it to stop after it gets to the

      random starting point again (so it doesn't repeat) and start up Group B (which isn't in there yet)

       

      var logos:Array = new Array();

      logos[0] = "logo1.swf";
      logos[1] = "logo2.swf";
      logos[2] = "logo3.swf";
      logos[3] = "logo4.swf";
      logos[4] = "logo5.swf";
      logos[5] = "logo6.swf";


      var totallogos = logos.length;
      var randlogo = Math.round(Math.random()*(totallogos-1));

      var framenum = 1;

      this.onEnterFrame = function() {
         
      //  trace(framenum);

          if (framenum == 1) {
             
              if (randlogo < (totallogos-1)) {
                  randlogo += 1;
              } else {
                  randlogo = 0;
              }

          trace("Number: " + randlogo);
          trace("Load Movie: " + logos[randlogo]);
          trace("---------------------------------");
         
          this.createEmptyMovieClip("holder_mc", 1);
          holder_mc.loadMovie(logos[randlogo], 1);
         

      //    placelogo(randlogo);
             
          }
             
          if (framenum < 30 ) {
              framenum += 1;
          } else {
              holder_mc.unloadMovie();
              framenum = 1;
          }

      }
        • 1. Re: How do I randomly start a list of swfs?
          kglad Adobe Community Professional & MVP

          do you play all the group A swfs before proceeding to group B swfs or to you only want the ones listed after the randomly chosen group A swf to play?

          • 2. Re: How do I randomly start a list of swfs?
            jare23 Level 1

            Yes I need all the SWF's in the list to play before proceeding to the next group.

            • 3. Re: How do I randomly start a list of swfs?
              kglad Adobe Community Professional & MVP

              try:

               

              var groupA:Array = [group A swfs];
              var groupB:Array = [group B swfs];

               

              this.createEmptyMovieClip("holder_mc",1);

               

              var playIndex:Number = Math.floor(Math.random()*groupA.length);
              var playedNum:Number = 0;
              var playingA:Boolean = true;

               

              holder_mc.loadMovie(groupA[playIndex]);
              this.onEnterFrame = function() {
                  if (playingA && holder_mc._totalframes>1 && holder_mc._currentframe>=holder_mc._totalframes) {
                      playedNum++;
                      if (playedNum<groupA.length) {
                          playAF();
                      } else {
                          playingA = false;
                          playIndex = Math.floor(Math.random()*groupB.length);
                          playedNum = 0;
                          holder_mc.loadMovie(groupB[playIndex]);
                      }
                  } else {
                      if (holder_mc._totalframes>1 && holder_mc._currentframe>=holder_mc._totalframes) {
                          playedNum++;
                          if (playedNum<groupB.length) {
                              playBF();
                          } else {

              delete this.onEnterFrame;
                              // all swfs played
                          }
                      }
                  }
              };

               

              function playAF() {
                  playIndex = (playIndex+1)%groupA.length;
                  holder_mc.loadMovie(groupA[playIndex]);
              }

               

              function playBF() {
                  playIndex = (playIndex+1)%groupB.length;
                  holder_mc.loadMovie(groupB[playIndex]);
              }

              • 4. Re: How do I randomly start a list of swfs?
                jare23 Level 1

                Thanks for your time!

                 

                I am getting errors on line 1.

                How exactly should I write my list of SWF's

                Should I continue with the numbered list?

                 

                groupA[0] = "logo_1.swf";
                groupA[1] = "logo_2.swf";
                groupA[2] = "logo_3.swf";

                etc.

                • 5. Re: How do I randomly start a list of swfs?
                  kglad Adobe Community Professional & MVP

                  var groupA:Array=["logo_1.swf","logo_2.swf"];

                  1 person found this helpful
                  • 6. Re: How do I randomly start a list of swfs?
                    jare23 Level 1

                    Thank You Thank You!

                     

                    That is exciting

                     

                    The ONLY thing now is that after it plays everything in group B it repeats the last SWF......I would like it to go back to Group A (in the same random/ordered fashion as before).

                    Is that a simple script?

                     

                    Thanks again!

                    • 7. Re: How do I randomly start a list of swfs?
                      kglad Adobe Community Professional & MVP

                      where it says

                       

                      // all swfs played

                       

                      is the section where you add the behavior you want after all the swfs have been played.

                       

                      please mark this thread as answered.

                      1 person found this helpful