4 Replies Latest reply on Oct 1, 2007 3:51 PM by ToonMariner

    rewind fastforward

    ToonMariner Level 1
      HI everyone.

      I am trying to create a fastforward/rewind button in flash. At present i am working on an audio file and I have got the track to advance/retrun 2 seconds on clicking the relevant button.

      What I would like to achieve is to loop this process while the user still has the mouse button down on the button.

      any suggestions owuld be vey much appreciated....
        • 1. Re: rewind fastforward
          kglad Adobe Community Professional & MVP
          use an onPress handler to start a setInterval (or onEnterFrame) loop and use an onRelease to clear you interval (or delete your onEnterFrame) loop.
          • 2. Re: rewind fastforward
            ToonMariner Level 1
            thnkyou!!!

            It kind of worked.

            This is teh code I am using - problem being teh fastforward/rewind works but the interval is not claered when the button is released...

            Can you spot anything obvious???

            function forwardSong():Void
            {
            pos = s.position + 2000;
            s.start(pos/1000);
            }

            function rewindSong():Void
            {
            pos = s.position - 2000;
            s.start(pos/1000);
            }

            rewindBttn.onPress = function()
            {
            var movebInterval = setInterval(rewindSong,500);
            }

            rewindBttn.onRelease = rewindBttn.onReleaseOutside = function()
            {
            clearInterval(movebInterval);
            }

            forwardBttn.onPress = function()
            {
            var movefInterval = setInterval(forwardSong,500);
            }

            forwardBttn.onRelease = forwardBttn.onReleaseOutside = function()
            {
            clearInterval(movefInterval);
            }


            the effect at the moment is that teh track either rewinds or forards until it reaches the start/end and even if I drag my scrubber into teh middle of teh track rewind/forward continues...

            Any help would be VERY much appreciated.
            • 3. Re: rewind fastforward
              kglad Adobe Community Professional & MVP
              when you use the var prefix for a variable name (like moveInterval) in a function body, you're making that variable local to the function.

              to remedy, remove the var prefix.
              • 4. Re: rewind fastforward
                ToonMariner Level 1
                kglad - you are a genius! many thanks...

                I use this code for video control too (different as file and using teh net straem object instead of teh sound object).

                However with the alteration of removing var the video still goes ape and doesn't break out of the loop.

                here is the code

                var nc:NetConnection = new NetConnection();
                nc.connect(null);

                var ns:NetStream = new NetStream(nc);
                var movefInterval;
                var movebInterval;

                videoPanel.attachVideo(ns);

                ns.addEventListener(NetStatusEvent.NET_STATUS, statusHandler);
                function statusHandler(myevent:NetStatusEvent):Void
                {
                if (
                myevent.info.code == "NetStream.Play.Stop"
                )
                {
                resetSong();
                }
                }

                ns.play(file);
                if (
                autostart == 1
                )
                {
                ns.seek();
                playPause.gotoAndStop('pause');
                }
                else
                {
                ns.seek(1);
                ns.pause();
                playPause.gotoAndStop('play');
                }

                function pauseIt():Void
                {
                ns.pause();
                }

                function playIt():Void
                {
                ns.pause();
                }

                function resetSong():Void
                {
                ns.seek(0);
                ns.pause();
                playPause.gotoAndStop('play');
                }

                function forwardSong():Void
                {
                ns.seek(Math.floor(ns.time + 1));
                }

                function rewindSong():Void
                {
                ns.seek(Math.floor(ns.time - 1));
                }

                playPause.onRelease = function()
                {
                if(this._currentframe == 10)
                {
                this.gotoAndStop('playOver');
                this._parent.pauseIt();
                }
                else
                {
                this.gotoAndStop('pauseOver');
                this._parent.playIt();
                }
                }

                backBttn.onRelease = function()
                {
                this._parent.resetSong();
                }

                rewindBttn.onPress = function()
                {
                movebInterval = setInterval(rewindSong,250);
                }

                rewindBttn.onRelease = rewindBttn.onReleaseOutside = function()
                {
                clearInterval(movebInterval);
                }

                forwardBttn.onPress = function()
                {
                movefInterval = setInterval(forwardSong,250);
                }

                forwardBttn.onRelease = forwardBttn.onReleaseOutside = function()
                {
                clearInterval(movefInterval);
                }

                Also the event handler i used for detecting teh end of teh track fails (using cs3 but coding for falsh 8 an AS 2)

                Thanks again...