3 Replies Latest reply on Apr 9, 2008 12:11 PM by FlashTastic

    Combobox + mp3 player

    alanwallace4 Level 1
      Hi,
      Im working on a mp3 player and im having some difficulties.

      I have the player loading in from xml. I have just added a combobox component so the user can scroll through the tracks and pick one.
      What i want is for the selected track to be loaded and play when the user selects it.
      At the moment i doesnt. Any help wold be very much apreciated. Here's the code.
      The combobox is called - playlist_lb

      var s:Sound = new Sound();
      s.onSoundComplete = playSong;
      s.setVolume(100);

      var sa:Array = new Array();

      var cps:Number = -1;

      var pos:Number;

      var xml:XML = new XML();
      xml.ignoreWhite = true;
      xml.onLoad = function()
      {
      var nodes:Array = this.firstChild.childNodes;
      for(var i=0;i<nodes.length;i++)
      {
      sa.push(new Song(nodes .attributes.url, nodes.attributes.artist, nodes .attributes.track));
      }
      playlist_lb.dataProvider=sa;
      playSong();
      }

      xml.load("songs.xml");

      function playSong():Void
      {
      s = new Sound();
      s.onSoundComplete = playSong;
      s.setVolume(100);
      mute.gotoAndStop("on");
      if(cps == sa.length - 1)
      {
      cps = 0;
      s.loadSound(sa[cps].earl, true);
      }
      else
      {
      s.loadSound(sa[++cps].earl, true);
      }
      trackInfo.text = sa[cps].artist + " - " + sa[cps].track;
      playPause.gotoAndStop("pause");
      textPos = 0;
      }

      function pauseIt():Void
      {
      pos = s.position;
      s.stop();
      }

      function unPauseIt():Void
      {
      s.start(pos/1000);
      }

      // Music Controls

      // Play/Pause Toggle
      playPause.onRollOver = function()
      {
      if(this._currentframe == 1) this.gotoAndStop("pauseOver");
      else this.gotoAndStop("playOver");
      }

      playPause.onRollOut = playPause.onReleaseOutside = function()
      {
      if(this._currentframe == 10) this.gotoAndStop("pause");
      else this.gotoAndStop("play");
      }

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

      // Next Button
      next.onRollOver = function()
      {
      this.gotoAndStop("nextOver");
      }

      next.onRollOut = next.onReleaseOutside = function()
      {
      this.gotoAndStop("next");
      }

      next.onRelease = function()
      {
      this._parent.playSong();
      }

      // Mute Button
      mute.onRollOver = function()
      {
      if(this._currentframe == 1) this.gotoAndStop("onOver");
      else this.gotoAndStop("offOver");
      }

      mute.onRollOut = mute.onReleaseOutside = function()
      {
      if(this._currentframe == 10) this.gotoAndStop("on");
      else this.gotoAndStop("off");
      }

      mute.onRelease = function()
      {
      if(this._currentframe == 10)
      {
      this.gotoAndStop("offOver");
      s.setVolume(0);
      }
      else
      {
      this.gotoAndStop("onOver");
      s.setVolume(75);
      }
      }
        • 1. Re: Combobox + mp3 player
          FlashTastic Level 1
          You'll need to create an eventListener to listen for the change event on your combobox.

          Cheers,
          Flashtastic
          • 2. Re: Combobox + mp3 player
            alanwallace4 Level 1
            Hi,
            Thanks FlashTastic. Ive popped the code n at the bottom but im no further forwards.
            In your code you have - //add code to play song.
            This is where im falling down. I tried entering playSong() but everytime i selected a song it just played the next song in the list rather than the selected one.
            Thanks
            Alan
            • 3. Re: Combobox + mp3 player
              FlashTastic Level 1
              The problem is that your playsong function doesn't take any arguments.

              Each time you call playsong, it has the logic in it to play the next song, not play a selected song, so you'll have to modify that function. Since your variable names are a bit cryptic, and you seem to have a custom object type of Song in there, it's a little harder to write code that might work.

              Look at the following example and you might be able to figure it out from there.

              Cheers,
              FlashTastic