1 Reply Latest reply on Aug 9, 2006 3:32 PM by Design_IQ

    Sound Volume Knob

    Design_IQ
      Hello Everyone,

      I am building a flash sound player and it uses knobs instead of sliders. I am having a hard time establishing the volume, and left to right balance. I have the panning control working left to right but not the sound to turn up and down working with a dynamically loaded MP3s.

      Anyone have an example or source files to make this work?

      I will post the code if no one has any examples.

      Thanks,
      DesignIQ
        • 1. Sound Volume Knob
          Design_IQ Level 1
          Frame Actions

          // Set Variables
          xmlPath = "mp3_info.xml";
          mp3Path = "mp3s/";
          track_num = 0;


          // Create a Movie Clip holder to attach things to
          this.createEmptyMovieClip("audio_looper", 1);


          // Function to play a sound from the library
          playLibrarySound = function (name, vol_level) {
          var mySound = new Sound();
          mySound.setVolume(vol_level);
          mySound.attachSound(name);
          mySound.start(0, 0);
          };


          // Function that scrolls the Song Details
          scrollDisplay = function () {
          if (id3Info.hscroll<id3Info.maxhscroll) {
          id3Info.hscroll++;
          } else {
          id3Info.hscroll = 0;
          }
          updateAfterEvent();
          };


          // Function that loads & streams our Mp3s
          loadMp3 = function () {
          unloadMp3();
          id3Info.hscroll = 0;
          audio = new Sound();
          audio.onLoad = function(success) {
          // null
          };
          audio.onSoundComplete = function() {
          if (track_num<totalNodes-1) {
          nextTrack();
          loadMp3();
          } else {
          unloadMp3();
          }
          };
          audio.loadSound(mp3Path+rootNode.childNodes[track_num].attributes.tFile, true);
          id3Info.htmlText = "";
          id3Info.htmlText += "<font color='#eeeeee'>. </font><font color='#CCCCCC'>TITLE: </font>"+rootNode.childNodes[track_num].attributes.tTitle+" <font color='#CCCCCC'>ARTIST: </font>"+rootNode.childNodes[track_num].attributes.tArtist+" <font color='#CCCCCC'>ALBUM: </font>"+rootNode.childNodes[track_num].attributes.tAlbum+" <font color='#CCCCCC'>YEAR: </font>"+rootNode.childNodes[track_num].attributes.tYear+" ";

          // call the scrolling function
          intervalID = setInterval(scrollDisplay, 10);
          audio_looper.onEnterFrame = function() {
          displayTime();
          };
          };


          // Function to unload any mp3 playing
          unloadMp3 = function () {
          clearInterval(intervalID);
          audio.stop();
          audio = new Sound();
          audio_time.text = "0:00";
          audio_looper.onEnterFrame = undefined;
          id3Info.htmlText = "";
          };


          // Function that displays the song's time info
          displayTime = function () {
          // duration output
          var durationMil = audio.duration;
          var durationSec = (durationMil/1000)/60;
          var durationSec = Math.round(durationSec*1000)/1000;
          // time elapsed
          var audioPos = audio.position;
          var pof = int(audioPos/1000);
          var psecs = int(pof%60);
          if (psecs<10) {
          psecs = "0"+psecs;
          }
          var timeFormat = int(pof/60)+":"+psecs;
          // display it
          audio_time.text = timeFormat;
          };


          // Display song details
          displayTrack = function () {
          track_title.text = rootNode.childNodes[track_num].attributes.tTitle;
          track_artist.text = rootNode.childNodes[track_num].attributes.tArtist;
          track_pos.text = (track_num+1)+" of "+totalNodes;
          };


          // Show the next track in the xml file
          nextTrack = function () {
          if (track_num<totalNodes-1) {
          track_num++;
          displayTrack();
          playLibrarySound("rollover_click", 100);
          }
          };


          // Show the previous track in the xml file
          previousTrack = function () {
          if (track_num>0) {
          track_num--;
          displayTrack();
          playLibrarySound("rollover_click", 100);
          }
          };


          // Create XML object to load our song info into
          loadTrackInfo = function () {
          tracks_xml = new XML();
          tracks_xml.ignoreWhite = true;
          tracks_xml.onLoad = function(success) {
          if (success) {
          rootNode = tracks_xml.firstChild;
          totalNodes = rootNode.childNodes.length;
          xml_status.text = "XML Loaded";
          displayTrack();
          } else {
          xml_status.text = "XML Load Failed";
          }
          };
          // Now that everything is set up, load the XML file
          tracks_xml.load(xmlPath);
          };


          // Tooltip functions v1.0
          // Uses dynamic tweening
          tooltipOn = function (ttLabel) {
          tooltip.gotoAndPlay("on");
          tooltip.tooltip_label = ttLabel;
          tooltip.onEnterFrame = function() {
          var newX = _xmouse;
          var newY = _ymouse;
          // set the speed here
          var variant = 7;
          // get current pos of the clip;
          var currentX = this._x;
          var currentY = this._y;
          // do the math
          var moveX = ((currentX-newX)/variant);
          var moveY = ((currentY-newY)/variant);
          // apply the math
          this._x = currentX-moveX;
          this._y = currentY-moveY;
          };
          };
          tooltipOff = function () {
          tooltip.onEnterFrame = undefined;
          tooltip.gotoAndPlay("off");
          };

          // Play Button
          button_play.onRelease = function() {
          loadMp3();
          playLibrarySound("rollover_click", 100);
          };
          button_play.onRollOver = function() {
          playLibrarySound("rollover_click", 100);
          tooltipOn("Play Mp3");
          };
          button_play.onRollOut = function() {
          tooltipOff();
          };


          // Stop Button
          button_stop.onRelease = function() {
          unloadMp3();
          playLibrarySound("rollover_click", 100);
          };
          button_stop.onRollOver = function() {
          playLibrarySound("rollover_click", 100);
          tooltipOn("Stop Audio");
          };
          button_stop.onRollOut = function() {
          tooltipOff();
          };


          // Next Button

          button_next.onRelease = function() {
          nextTrack();
          loadMp3();
          playLibrarySound("rollover_click", 100);
          };
          button_next.onRollOver = function() {
          playLibrarySound("rollover_click", 100);
          tooltipOn("Next Track");
          };
          button_next.onRollOut = function() {
          tooltipOff();
          };


          // Previous Button
          button_previous.onRelease = function() {
          previousTrack();
          loadMp3();
          playLibrarySound("rollover_click", 100);
          };
          button_previous.onRollOver = function() {
          playLibrarySound("rollover_click", 100);
          tooltipOn("Previous Track");
          };
          button_previous.onRollOut = function() {
          tooltipOff();
          };


          // Buffer Animation
          buffer_animation.onEnterFrame = function() {
          // show?
          if (audio.position == 0) {
          this._visible = 1;
          } else {
          this._visible = 0;
          }
          };

          // Begin
          loadTrackInfo();


          MovieClip Actions

          /*
          set maximum rotation of the knob.
          read initial volume of sound and set corresponding position of knob.
          */
          onClipEvent(load){
          //maximum angle of rotation for the knob
          maxRotAngle = 120;

          //read the initial volume & set the position of the knob
          this.rotbutton._rotation = (2*_root.s.getVolume() - 100)*maxRotAngle/100;

          //read the initial pan and set the position of the knob
          //this.rotbutton._rotation = _root.s.getPan() * maxRotAngle/100;
          }

          /*
          set the volume depending on the position of the knob
          use forumla to convert _rotation into volume or pan range
          */
          onClipEvent(enterFrame){
          if (rotbutton.dorotate) {
          _root.s.setVolume(Math.floor((100+this.rotbutton._rotation/maxRotAngle*100)/2));
          //_root.s.setPan(Math.floor((this.rotbutton._rotation/maxRotAngle*100)));
          }

          //update readouts...
          _root.sovolume = _root.s.getVolume();
          _root.dialangle = this.rotbutton._rotation;
          }

          ///////////////////////*


          Help, I know it's something stupid I just am missing. Thanks