2 Replies Latest reply on Mar 5, 2013 5:26 PM by genoism

    need some help on fixing a playback issue

    genoism Level 1

      I have this code(sorry that it's messy it's not actually mine, but i do have to fix it ><)...this script controls a player. The player has a playhead. The problem with the playhead is

      1) When the user drags the playhead when it's paused, the playhead will continue moving...i can't figure out how to stop it! (However if the player is playing, dragging the playhead should not pause it.

       

      2) If the user drags the playhead while paused and clicks play...the player will turn the sound on...but not continue playing....

       

      I have a feeling it's a simple fix but i know very little about actionscript. You can see i tried to fix it in the comment /* section but failed horribly...

       

      Any advice on how to fix this bug?

       

      Many thanks in advance...here is the code

       

      var isPlaying:Boolean = false;

      var currentclip:MovieClip;

      var intervalID:Number;

      var intervalID2:Number;

      var plen:Number = 450;

      var sX:Number = -231.75;

      var eX:Number = 248.25;

      var clipTotalFrames:Number;

      var clipCurrentFrame:Number;

      var mySound:Sound;

      var soundPosition:Number = 0;

      var audioInterval:Number = 0;

      var vol:Number;

      var isFading:Boolean = false;

       

       

       

       

      function initapp () : Void {

                mySound = new Sound();

                mySound.attachSound("talk");

                mySound.onSoundComplete = function () {

                          soundPosition = 0;

                          playAudio();

                };

                clearAllClips();

                createButtons();

                initUIControls();

                uiclip.playicon._visible = true;

                uiclip.pauseicon._visible = false;

       

                clicktoplay.onRelease = function () {

                          seletTab("b1");

                          this._visible = false;

                }

      }

       

       

      // AUDIO Controls

       

       

      function playAudio () : Void {

                trace("called");

                mySound.start(soundPosition,0);

                soundPosition = 1;

      }

      function stopAudio () : Void {

                soundPosition = Math.round(mySound.position/1000);

                mySound.stop();

      }

      function fadeOutAudio () : Void {

                vol = 100;

                audioInterval = setInterval(fadeOut, 100);

                isFading = true;

      }

      function fadeOut() : Void {

                vol -= 8;

                mySound.setVolume(vol);

                // put an if condition to restrict the increment in volume after it reaches to 100

                if (vol<=0) {

                          clearInterval(audioInterval);

                          mySound.setVolume(0);

                          uiclip.volumeButton.gotoAndStop(2);

                          mySound.stop();

                          soundPosition = 0;

                          stopAudio();

                          isFading = false;

                          soundPosition = 0;

                          trace("soundPosition = " + soundPosition);

                }

      }

      function manualPP () : Void {

                if (mySound.getVolume() == 0) {

                                    mySound.setVolume(100);

                                    uiclip.volumeButton.gotoAndStop(1);

                                    playAudio();

                          } else {

                                    mySound.setVolume(0);

                                    uiclip.volumeButton.gotoAndStop(2);

                                    stopAudio();

                          }

      }

      // END AUDIO Controls

       

       

      function initUIControls () : Void {

                uiclip.playButton.onRelease = function () {

                          clearInterval(intervalID);

                          clearInterval(intervalID2);

                          doPlayPause();

                          manualPP();

                          doPlayHead("play");

                }

       

                uiclip.playhead.onPress = function () {

                          clearInterval(intervalID);

                          clearInterval(intervalID2);

                          doPlayHead();

                          uiclip.playicon._visible = true;

                          uiclip.pauseicon._visible = false;

                          currentclip.stop();

                          isPlaying = false;

                          intervalID2 = setInterval(scrubPlayHead, 10);

                          startDrag(this, false, -231.75, this._y, 218.25, this._y);

                }

                uiclip.playhead.onRelease = uiclip.playhead.onReleaseOutside = function () {

                          stopDrag();

                          clearInterval(intervalID2);

                          /*if (uiclip.pauseicon._visible == false) {

                          //mySound.setVolume(0);

                          //doPlayPause();

                          doPlayHead("play");

                          //currentclip.stop();

                          trace("play icon is visible? if won");

                          }

                          else {

                          currentclip.stop();

                          //mySound.setVolume(100);

                          uiclip.playicon._visible = false;

                          uiclip.pauseicon._visible = true;

                          trace("else won");

                          doPlayPause();

                          //doPlayHead("play");

       

                }*/

                doPlayPause();

                doPlayHead("play");

                }

       

                uiclip.volumeButton.onRelease = function () : Void {

                          if (mySound.position == 0) return;

                          if (mySound.getVolume() == 0) {

                                    mySound.setVolume(100);

                                    this.gotoAndStop(1);

                                    playAudio();

                          } else {

                                    mySound.setVolume(0);

                                    this.gotoAndStop(2);

                                    stopAudio();

                          }

                }

      }

      function doPlayHead (action:String) : Void {

                if (action == "play") {

                          intervalID = setInterval(playPlayHead, 10);

                } else {

                          clearInterval(intervalID);

                }

      }

       

       

      function playPlayHead () : Void {

                playHeadCalculator();

      }

      function playHeadCalculator () : Void {

                clipTotalFrames = currentclip._totalframes;

                clipCurrentFrame = currentclip._currentframe;

       

                var posPercent:Number = (clipCurrentFrame / clipTotalFrames) * 100;

                var newXplus = (posPercent * .01) * plen;

                uiclip.playhead._x = sX + newXplus;

                uiclip.mybarmask._x = uiclip.playhead._x - 456.5;

                if (currentclip._currentframe == currentclip._totalframes) {

                          currentclip.stop();

                          clearInterval(intervalID);

                          clearInterval(intervalID2);

                          doPlayPause();

                          if (currentclip._name == "reqclip") {

                                    fadeOutAudio();

                          }

                }

      }

      function scrubPlayHead () : Void {

                var posPercent:Number = ((uiclip.playhead._x + 232) / plen) * 100;

                var newXplus = Math.round((posPercent * .01) * currentclip._totalframes);

                currentclip.gotoAndStop(newXplus);

                uiclip.mybarmask._x = uiclip.playhead._x - 456.5;

                //trace("scrubbed the playhead");

      }

      function resetPlayHead () : Void {

       

      }

       

       

      function doPlayPause () : Void {

                if (isPlaying) {

                          uiclip.playicon._visible = true;

                          uiclip.pauseicon._visible = false;

                          currentclip.stop();

                          isPlaying = false;

                          clearInterval(intervalID);

                          clearInterval(intervalID2);

                } else {

                          uiclip.playicon._visible = false;

                          uiclip.pauseicon._visible = true;

                          if (currentclip._currentframe != currentclip._totalframes) {

                                    currentclip.play();

                          } else {

                                    currentclip.gotoAndPlay(2);

                          }

                          isPlaying = true;

                }

      }

       

       

      function createButtons () : Void {

                for (var i:Number = 1; i < 5; i++) {

                          uiclip["b" + i].isSelected = false;

                          uiclip["b" + i].ID = "b" + i;

                          uiclip["b" + i].onRelease = function () {

                                    seletTab(this.ID);

                          }

                          uiclip["b" + i].onRollOver = function () {

                                    if (this.isSelected == false) {

                                              // this.gotoAndStop(2);

                                    }

                          }

                          uiclip["b" + i].onRollOut = uiclip["b" + i].onReleaseOutside = function () {

                                    if (this.isSelected == false) {

                                              // this.gotoAndStop(1);

                                    }

                          }

                }

                uiclip.b1.isSelected = true;

                uiclip.b1.gotoAndStop(2);

       

                intclip._visible = true;

                intclip.gotoAndStop(1);

                currentclip = intclip;

      }

       

       

      function seletTab (idname:String) : Void {

                var skipReset = false;

                switch (idname) {

                          case "b1" :

                                    if (intclip == currentclip) {

                                              skipReset = true;

                                    }

                                    break;

                          case "b2" :

                                    if (benclip == currentclip) {

                                              skipReset = true;

                                    }

                                    break;

                          case "b3" :

                                    if (reqclip == currentclip) {

                                              skipReset = true;

                                    }

                                    break;

                          case "b4" :

                                    if (faqclip == currentclip) {

                                              skipReset = true;

                                    }

                                    fadeOutAudio();

                                    break;

                }

       

                if (skipReset == false) {

                          if (isPlaying) {

                                    uiclip.playicon._visible = true;

                                    uiclip.pauseicon._visible = false;

                                    currentclip.stop();

                                    isPlaying = false;

                          }

                          clearAllClips();

                          doPlayHead();

                }

       

                clearInterval(intervalID);

                clearInterval(intervalID2);

       

                switch (idname) {

                          case "b1" :

                                    intclip._visible = true;

                                    intclip.gotoAndPlay(2);

                                    currentclip = intclip;

                                    uiclip.b1.isSelected = true;

                                    uiclip.b1.gotoAndStop(2);

                                    break;

                          case "b2" :

                                    benclip._visible = true;

                                    benclip.gotoAndPlay(2);

                                    currentclip = benclip;

                                    uiclip.b2.isSelected = true;

                                    uiclip.b2.gotoAndStop(2);

                                    break;

                          case "b3" :

                                    reqclip._visible = true;

                                    reqclip.gotoAndPlay(2);

                                    currentclip = reqclip;

                                    uiclip.b3.isSelected = true;

                                    uiclip.b3.gotoAndStop(2);

                                    break;

                          case "b4" :

                                    faqclip._visible = true;

                                    faqclip.gotoAndPlay(2);

                                    currentclip = faqclip;

                                    uiclip.b4.isSelected = true;

                                    uiclip.b4.gotoAndStop(2);

                                    break;

                }

                isPlaying = true;

                uiclip.playicon._visible = false;

                uiclip.pauseicon._visible = true;

                trace(idname + " - " + isFading + " - " + soundPosition);

                if (idname != "b4" && isFading == true) {

                          clearInterval(audioInterval);

                          mySound.setVolume(0);

                          uiclip.volumeButton.gotoAndStop(2);

                          stopAudio();

                          soundPosition = 0;

                          isFading = false;

                }

                if (idname != "b4" && soundPosition == 0) {

                          mySound.setVolume(100);

                          playAudio("talk");

                          uiclip.volumeButton.gotoAndStop(1);

                }

                doPlayHead("play");

      }

       

       

      function clearAllClips () : Void {

                for (var i:Number = 1; i < 5; i++) {

                          uiclip["b" + i].isSelected = false;

                          uiclip["b" + i].gotoAndStop(1);

                }

                benclip._visible = false;

                benclip.gotoAndStop(1);

                reqclip._visible = false;

                reqclip.gotoAndStop(1);

                intclip._visible = false;

                intclip.gotoAndStop(1);

                faqclip._visible = false;

                faqclip.gotoAndStop(1);

                isPlaying = false;

      }

      initapp();