11 Replies Latest reply on Apr 24, 2006 8:53 AM by rodolfo1216

    How to make an swf scrubber

    rodolfo1216 Level 1
      I'd like to put a scrub bar at the top of my movie so users can scrub back and forth through it. I've found a couple pre-built ones at Flashkit.com, but I really would like to learn how to make one myself. Anyone have any suggestions?

      Thanks,

      Michael
        • 1. Re: How to make an swf scrubber
          kglad Adobe Community Professional & MVP
          to make a scrubber (or scrollbars) set-up two (linear) equations in two unknowns. you know the location of your scrubber when it's at each extreme of its range and you know the frames of your timeline (1 and _totalframes) that you want to reference when the scrubber is those extremes. solve for your two unknowns.

          you have an equation that gives the frame as function of the scrubber's position and you have an equation that gives the scrubber's position as a function of the timeline's frame.
          • 2. Re: How to make an swf scrubber
            rodolfo1216 Level 1
            I think I've almost got it, but if anyone wants to give me a little help - it would be much appreciated. I've created the scrubber (called knob_mc) and a track to scrub it on and I've figured out the equation that relates the scrubber to the main timeline (and put this inside a function called "calculate"). Now I'm just not sure what to do to make the timeline move when the user presses on the knob? Here's my code so far:

            function calculate(){
            var amount:Number = (knob_mc._x / track._width) * 100;
            }
            knob_mc.onPress=function(){
            _root.stop();
            this.startDrag(false,0, this._y, track._width,this._y);
            this.onMouseMove = calculate;
            }

            knob_mc.onRelease = knob_mc.onReleaseOutside = function(){
            this.stopDrag();
            _root.play();
            }

            Thanks for the help,

            Michael
            • 3. How to make an swf scrubber
              quethenoo
              Would something like this work?

              function calculate(){
              var amount:Number = (knob_mc._x / track._width) * 100;
              var frameNum:Number = Math.round(amount);
              }
              knob_mc.onPress=function(){
              _root.stop();
              this.startDrag(false,0, this._y, track._width,this._y);
              this.onMouseMove = calculate;
              }

              knob_mc.onRelease = knob_mc.onReleaseOutside = function(){
              this.stopDrag();
              _root.gotoAndPlay(frameNum);
              }

              he types hopefully.........
              • 5. Re: How to make an swf scrubber
                rodolfo1216 Level 1
                That did it. Works perfectly. Slight typo in the code though: you have to take the F off of calculate. Then it works great. Only one more piece of navigation that seems necessary: I want the knob_mc to move along the track during the movie. Then the movie should stop when you press on the knob to scrub though the movie. I tried this (note: the track is 100 pixels long and the movie is 100 frames long):

                knob_mc.onEnterFrame = function(){
                this._x = _root._currentframe;
                }

                but using onEnterFrame in this way gave me quirky results - the knob keeps moving even though I'm pressing on it. Any help on this is much appreciated!

                Thanks!

                Michael
                • 7. Re: How to make an swf scrubber
                  rodolfo1216 Level 1
                  Cool. Here's the story: it works perfectly the very first time you click on the knob, but if you release and then press again, you start to get quirky results - the knob seems to resist following the cursur. Can't quite figure out why.

                  Thanks again for working with me on this,

                  Michael
                  • 8. Re: How to make an swf scrubber
                    kglad Adobe Community Professional & MVP
                    that code should work without problem as long as it is executed only once. if that code is in a frame that loops, you'll have a problem unless you place that setInterval() that's attached to the repeating frame within a conditional:
                    • 9. Re: How to make an swf scrubber
                      rodolfo1216 Level 1
                      I'm sorry - I've been tinkering around with your additional code for a while but I just can't get the whole thing to work. I guess this idea of a movie scrubber is a bit more complicated that I originally thought. I'm just not sure how to integrate the new code with the old code. Sorry to bother you with this again, but it looks like you may just have to spell it out for me. I'm learning as I go, and this is a thorny one.

                      Thanks for your help,

                      Michael
                      • 10. Re: How to make an swf scrubber
                        kglad Adobe Community Professional & MVP
                        the complete code is below:

                        • 11. Re: How to make an swf scrubber
                          rodolfo1216 Level 1
                          That's it. Everything works perfectly. Thanks again for your time and patience.

                          Michael