3 Replies Latest reply on Mar 11, 2009 1:04 PM by Webshark2000

    Play a movieclip in reverse

    Webshark2000 Level 1
      I'm creating a movieclip that shows some photo samples with two arrows at the bottom. I want it so that if the user presses on the right arrow, the movie clip plays forward and goes toward the end to "shuffle" through the image samples. But I would also like them to be able to press on the left arrow and be able to play the movieclip backwards to "shuffle" back toward the beginning of the images.

      The closest thing I can think of that would be similar to this would be the way you can shuffle through album images in iTunes.

      I just need to know the Actionscript 2.0 code to play the movieclip in reverse.

      Thanks.
        • 1. Re: Play a movieclip in reverse
          robdillon Most Valuable Participant
          You can use the prevFrame() method to move to the previous frame in a movieClip. To use this in a continuous animation to show the clip in reverse, just put that method inside an enterframe method. Something like:

          button.onRelease = function() {
          movieClip.onEnterFrame = function() {
          if(this._currentframe > 1) {
          this.prevFrame();
          } else {
          delete movieClip.onEnterFrame;
          }
          }
          }

          or, in AS3:

          button.addEventListener(MouseEvent.MOUSE_UP, onUp);

          function onUp(event:MouseEvent):void {
          movieClip.addEventListener(Event.ENTER_FRAME,onEf);
          }

          function onEf(event:Event):void {
          var thisClip:Object = event.target;
          if(thisClip.currentFrame > 1) {
          thisClip.prevFrame();
          } else {
          thisClip.removeEventListener(Event.ENTER_FRAME,onEf);
          }
          }

          That's off the top of my head, so it may need some tuning. In either case, substitute the actual button instance name for "button" and the actual movieClip's instance name for "movieClip".
          • 2. Re: Play a movieclip in reverse
            Webshark2000 Level 1
            I decided to allow the user to simply roll over the images to advance and rewind the thumbnails. If they're on the right side of the middle I want it to "shuffle" to the right, if they're on the left, "shuffle" to the left (or play the movieclip backwards until they roll out or reach the first frame of the movieclip). How would I accomplish this if the thumbnails themselves are movieclips (I did this so I only had to create one instance for all the images).

            To roll it to the right I simply used this code on the thumbnails:

            on(rollOver){
            _parent.play();
            }
            on(rollOut){
            _parent.stop();
            }

            What would I need to put on the ones on the left?

            Would it be something like:

            on(rollOver) {
            if(_parent._currentframe > 1) {
            _parent.prevFrame();
            }
            }
            on(rollOut){
            _parent.stop();
            }

            Of course this doesn't work because it only calls it once when the thumbnails are rolled over.
            • 3. Re: Play a movieclip in reverse
              Webshark2000 Level 1
              I settled on a solution, maybe not the best one, but it works.

              I made a movieclip which goes to frame 2 on rollOver:

              on(rollOver){
              gotoAndStop(2);
              _global.backward = 1;
              }
              on(rollOut){
              gotoAndStop(1);
              _global.backward = 0;
              _parent.stop();
              }

              On the second frame of that movielcip I placed another movieclip outside of the stage and put the following code on it:

              onClipEvent(enterFrame){
              _parent._parent.gotoAndStop(_parent._parent._currentframe - 1);
              if(_parent._parent.tn1._currentframe != 1 && _parent._parent._currentframe == 1) {
              _parent._parent.gotoAndStop(33);
              }
              }

              The extra code about going to frame 33 is to get the main movieclip with the picture thumbnails to loop and the check to make sure tn1 isn't on frame 1 is just to make it stop going backward once it's at the very beginning of the photos. The _global.backward variable it just to make sure the pictures cycle properly.

              Instead of having a really long movieclip with numerous photos scrolling from offscreen I just made one movieclip and put each photo thumbnail on a seperate frame within it. Then, I just put six instances of that movieclip on the screen at one time and once the first one has gotten offscreen I just have some code cycle all of them so it looks like one continuous scroll.

              The only problem I'm still having is that when it loops in reverse (meaning it jumps from frame 1 to frame 33) there is a slight jerking of all the thumbnails. I'm not sure why this is happening because when playing forward, they look perfectly smooth even when the movieclip loops.

              If anyone has a suggestion, let me know.

              Thanks.