3 Replies Latest reply on Aug 24, 2009 10:23 AM by kglad

    Getting a custom dragger to work on Audio Player

    brostd

      I am trying to get this dragger to work on the play head of my audio player. I get it to drag but when i let go it jumps back to the place it was before. Not sure if I am over my head here but any help would be great.

      You may need to change the sound file to get it to work but I have attached all other files needed to get it to work.

       

       

      var XMLLoaded:XML = new XML();
      XMLLoaded.ignoreWhite = true;
      var timesLoaded:Number = 0;
      this.createEmptyMovieClip("sound_mc", this.getNextHighestDepth);
      var sound_mc:Sound = new Sound();
      var finished:Boolean = false;
      var XMLSnippits:XML = new XML();
      var sStart:Array = new Array;
      var sText:Array = new Array;

             
      XMLLoaded.onLoad = function(bSuccess:Boolean):Void {
          var timerStarted:String = "no";
          if (bSuccess){
              if(XMLLoaded.firstChild.childNodes[0].childNodes[0].nodeValue == "yes"){
                  trace(timerStarted + " timer status");
                  clearInterval(XMLTimer);
                  fileAdded();
              }else{
                  if(timesLoaded == 10){
                      trace("There has been an Error Loading this file");
                      clearInterval(XMLTimer);
                  }else{
                     
                  }
              }
          }
      }

      function loadXML():Void {

          XMLLoaded.load("call-process-yes.xml");
          timesLoaded += 1
          trace("XML has been loaded " + timesLoaded);
      }

      var XMLTimer:Number = setInterval(loadXML, 3000)
      loadXML();

      function fileAdded():Void {


          trace(sStart);
          play_btn._visible = false;
          pause_btn._visible = true;
          words.html = true;
          sound_mc.loadSound("BigGreenTractor.mp3", false);
         
          XMLSnippits.ignoreWhite = true;

          XMLSnippits.onLoad = function(bSucess:Boolean):Void{
              if (bSucess){
                  var snippitLength:Number =  XMLSnippits.firstChild.childNodes[3].childNodes.length;
                  trace(snippitLength + " this is the length");
                  for(var j:Number = 0; j < snippitLength; j++){
                      sStart[j] = XMLSnippits.firstChild.childNodes[3].childNodes[j].childNodes[0].childNodes[0].nodeValue;
                      sText[j] = XMLSnippits.firstChild.childNodes[3].childNodes[j].childNodes[4].childNodes[0].nodeValue;
                  }
                  //var sStart:Number = 53;
                  //var sEnd:Number = 234;
                  addMarkers();
                  trace("Sucess");
                  trace(sStart);
              }else{
                  trace("Failed");
              }
          }

          XMLSnippits.load("call-meta-data.xml");

          function addMarkers():Void {
             
              var totalSecs:Number = sound_mc.duration /1000 ;
                  var secLength:Number = timeline.loader._width / totalSecs
                  for(var i:Number = 0; i < sStart.length; i++){
                      timeline.attachMovie("marker", "marker" + i, i);
                      timeline["marker" + i]._x = sStart[i] * secLength;
                      timeline["marker" + i]._y = -5;
                      trace(i);
                      trace(totalSecs);
                     
                  }
             
                 
                  var sS = setInterval(soundStatus, 100);
          }


          function soundStatus(){
              var amountLoaded = sound_mc.getBytesLoaded() / sound_mc.getBytesTotal();
              var time = sound_mc.duration;
              var position = sound_mc.position;
              timeline.loader.loader._width = amountLoaded * 378;
              timeline.playHead._x = position / time * 378;
             
          }

          sound_mc.onLoad = function (bSucess:Boolean):Void{
              if (bSucess) {
                  this.start();
              }
          }

          sound_mc.onSoundComplete = function():Void {
              finished = true;
              play_btn._visible = true;
              pause_btn._visible = false;
              words.htmlText = "Please choose a marker";
          }
         
          play_btn.onRelease = function():Void{
              if(finished){
                  sound_mc.start();
                  finished = false;
              }else{
                  sound_mc.stop();
                  sound_mc.start(sound_mc.position/1000);
              }
              pause_btn._visible = true;
              play_btn._visible = false;
          }   

          pause_btn.onRelease = function():Void{
         
              sound_mc.stop();
              pause_btn._visible = false;
              play_btn._visible = true;
              stopInterval();
          }
         

          timeline.playHead.onPress = function ():Void{
              startDragger();
              clearInterval(sS);
          }
         
          timeline.playHead.onRelease = function ():Void{
              stopDragger();
             
             
          }
         
          timeline.playHead.onReleaseOutside = function ():Void {
              stopDragger();
          }
         
          function startDragger():Void {
              var leftLimit = timeline.loader._x;
              var rightLimit = timeline.loader._width + timeline.loader._x;
              sound_mc.stop();
              play_btn._visible = false;
              pause_btn._visible = true;
              startDrag(timeline.playHead, false, leftLimit, timeline.loader._y, rightLimit, timeline.loader._y);
             
          }
         
          function stopDragger():Void {
              var soundLength = sound_mc.duration / 1000;
              stopDrag();
              sound_mc.stop();
              sound_mc.start(timeline.playHead._x / timeline._width * soundLength);
              trace(timeline.playHead._x / timeline._width * soundLength);
              var sStatus = setInterval(soundStatus,100);
          }
      }