8 Replies Latest reply on May 4, 2007 10:12 AM by TaylorTay619

    Easy timeline question

    TaylorTay619
      Hey peeps! I have a question about the time line. I have two buttons controlling the time line one makes the time line go one frame forward and the other makes the time line go one frame back. Now what I want to do is, if you are on the last frame and you click again it will take you to the beginning of the time line and if you are on the first frame and you click the back button it will take you to the end of the frames. Any help would be greatly appreciated! The code I currently have written is at the bottom.

      Thanks!

      t2.onPress = function() {
      torso.nextFrame();
      }

      t1.onPress = function() {
      torso.prevFrame();
      }
        • 1. Re: Easy timeline question
          Rothrock Level 5
          Let's just do the forward one at the moment. So basically you want to ask, if the current frame is the same one as the last one, I should go to the first frame, otherwise just go one more forward.

          Then you break out the handy F1 help files. You are dealing with MovieClips so you head right to the Actionscript Dictionary Classes and scroll down past Array, LoadVars, until you get to M for MovieClip. Then you read through and look for properties that might tell you the things you need. Finally you come up with this.

          if(torso._currentFrame==torso._totalframes){
          torso.gotoAndStop(1);
          } else {
          torso.nextFrame();
          }

          The reverse is left as an exercise for the reader. :)
          • 2. Re: Easy timeline question
            TaylorTay619 Level 1
            that worked perfectly! Thanks! Ok I will try to get it to go in reverse.
            Thanks so much!
            • 3. Re: Easy timeline question
              Rothrock Level 5
              Glad that will work for you. I figure what fun is it if ALL the answers are given to you. But if you do run into trouble post back. (Actually post back anyways with what you come up with.)
              • 4. Re: Easy timeline question
                TaylorTay619 Level 1
                Ok will do :)
                • 5. Re: Easy timeline question
                  TaylorTay619 Level 1
                  Ok this is what I have for going backward, but it does not work. I am still lost

                  t1.onPress = function() {
                  if(torso._currentFrame==-1){
                  torso.gotoAndStop(_totalframes);
                  } else {
                  torso.prevFrame();
                  }
                  }
                  • 6. Re: Easy timeline question
                    Rothrock Level 5
                    Why would you test if the _currentframe was -1? It is a fine guess, but I'm just wondering why you guessed it? If you check it out with a trace or something you will see the first frame is always 1. Remember we aren't testing for the frame it would be on after the click is done, we are testing for the frame it is on right now.

                    Now you've done something very clever here, but it probably also is part of the problem. It was great that you used _totalframes as the argument for the gotoAndStop. A lot of folks would have said "Oh, my torso movie has 20 frames so I'll put twenty there." But then a lot of folks would have to add or delete a frame from the torso movie and then forget to change the 20. And then it wouldn't work properly. (Okay, so the lot of folks would have been me until I got burned by this same thing a few times!)

                    So using that was great intuition, skill, what have you.

                    The tricky thing is you haven't told Flash _totalframes of what. You might be thinking "Well I'm telling the torso movie to gotoAndStop, so Flash should know that I mean the _totalframes of the torso movie." But Flash won't assume things like that. You might be trying to keep flash in synch with some other movieclip or something. So you need something like this:

                    torso.gotoAndStop(torso._totalframes);
                    • 7. Re: Easy timeline question
                      Rothrock Level 5
                      Why would you test if the _currentframe was -1? It is a fine guess, but I'm just wondering why you guessed it? If you check it out with a trace or something you will see the first frame is always 1. Remember we aren't testing for the frame it would be on after the click is done, we are testing for the frame it is on right now.

                      Now you've done something very clever here, but it probably also is part of the problem. It was great that you used _totalframes as the argument for the gotoAndStop. A lot of folks would have said "Oh, my torso movie has 20 frames so I'll put twenty there." But then a lot of folks would have to add or delete a frame from the torso movie and then forget to change the 20. And then it wouldn't work properly. (Okay, so the lot of folks would have been me until I got burned by this same thing a few times!)

                      So using that was great intuition, skill, what have you.

                      The tricky thing is you haven't told Flash _totalframes of what. You might be thinking "Well I'm telling the torso movie to gotoAndStop, so Flash should know that I mean the _totalframes of the torso movie." But Flash won't assume things like that. You might be trying to keep flash in synch with some other movieclip or something. So you need something like this:

                      torso.gotoAndStop(torso._totalframes);
                      • 8. Re: Easy timeline question
                        TaylorTay619 Level 1
                        Thanks so much for your help and interest in teaching me something new. I am grateful.