6 Replies Latest reply on Mar 14, 2011 3:08 PM by Skoolbus777

    Set frames to play: (frame 1, frame 3, frame 5)?

    Skoolbus777 Level 1

      I hope I can ask this correctly. I'll paraphrase.

       

      press_mc.onRelease = function(){

      mover2_mc.play()};

       

      This is a snippet of some code I'm working on. Currently I have a mc that you press that plays another mc. That mc that reacts has 5 frames, each frame with stop(); on each frame. I do a normal play code because it lets me play through and cycle back to frame 1 after frame 5 (so if I click the mc it eventually cycles back to the first frame and starts the process over again). If I do a nextframe it stops at frame 5, so that's why I use play.

       

      press_mc click on it and it tells mover2_mc to advance a frame and recycles back to frame one to redo the process.

       

      Can I tell press_mc to play and skip a frame or to have it play a list of frames that I tell? I can't do a _currentframe +2 because it'll halt at frame 5.

        • 1. Re: Set frames to play: (frame 1, frame 3, frame 5)?
          kglad Adobe Community Professional & MVP

          you can use an array of frame numbers or labels to direct a movieclip to a sequence of frames.

          1 person found this helpful
          • 2. Re: Set frames to play: (frame 1, frame 3, frame 5)?
            Skoolbus777 Level 1

            Kglad,

             

            Thanks for your help. I've never created an array before so I Googled and I think I understand. So please let me know if something like this would potentially work. Most code samples or tutorials are based on trace statements and not frame scripts, so hopefully I got this nearly correct.

             

            I figured I define an array, list the array entries and their corresponding code. And then call on the array to play in which it would cycle the frames based on the array definition.

             

             

            var frameset = new Array();

            frameset[0] = movie_mc.gotoAndPlay(2);

            frameset[1] = movie_mc.gotoAndPlay(4);

            frameset[2] = movie_mc.gotoAndPlay(6);

            frameset[3] = movie_mc.gotoAndPlay(8);

             

            press_mc.onRelease = function(){

            framest.play()};

            • 3. Re: Set frames to play: (frame 1, frame 3, frame 5)?
              kglad Adobe Community Professional & MVP

              try:

               


               

               

              var frameset:Array = new Array(2,4,6,8);

              var index:Number=0;

               

              press_mc.onRelease = function(){

              gotoAndPlay(frameset[index]);

              index=(index+1)%frameset.length;

              }

              • 4. Re: Set frames to play: (frame 1, frame 3, frame 5)?
                Skoolbus777 Level 1

                var frameset:Array = new Array(1,2);

                var index:Number=0;

                 

                CAPS_mc.onRelease = function(){

                keyboards.gotoAndPlay(frameset[index]);

                index=(index)%frameset.length;

                }

                 

                 

                 

                Kglad,

                 

                You are the man! Few things... I put the name of my mc infront of the gotoAndPlay and then I removed the +1 after (index... at first it played frame 1,2,3, then afterwards it played and cycled thru 1 and 2. I removed the +1 and it no longer plaid the frame 3 (the +1 added frame 3 for some reason).

                 

                could you brief me on the meaning of:

                index=(index)%frameset.length; ?

                 

                Thanks so much this is awesome!

                • 5. Re: Set frames to play: (frame 1, frame 3, frame 5)?
                  kglad Adobe Community Professional & MVP

                  index=(index)%frameset.length;

                   

                  assigns the remainder of index/frameset.length to index.  the above, does nothing useful unless index is greater than or equal to frameset.length.  using the code i suggested allows index to cycle through the indices of frameset, repeatedly.

                   

                  your problem is caused by using gotoAndPlay (as opposed to gotoAndStop) AND using adjacent frames.  to remedy, change one, or both, those.

                  • 6. Re: Set frames to play: (frame 1, frame 3, frame 5)?
                    Skoolbus777 Level 1

                    Awesome. I need to google the symbols such as % since this is the first time I've seen it in AS. Thanks again.