1 Reply Latest reply on Jun 26, 2007 1:30 PM by waterox

    mp3 player with 3 listboxes and category/subcategory

    waterox
      Hi,

      I am trying to hack this mp3 player so that it displays 3 levels of hierarchy instead of 2. Check out the current player here http://www.yanwhite.com/staging/GetGoodMusic/music.htm

      Currently it has kind of 3 levels, but using 2 buttons for the top level.
      I want all 3 as list boxes. So that listbox1 has main categories, listbox2 displays subcategories and listbox3 displays the tracks.

      Here is the actionscript..

      //setting it up
      //change path to your own
      path = " http://billwatson2.no-ip.info/public/flash/music/";
      loadBB.setLabel("By Mood");
      loadB.setLabel("By Genre");
      pause.setLabel("Pause");
      playB.setLabel("Play");
      pause.setEnabled(false);
      playB.setEnabled(false);
      //constucting menu system
      //next few functions just allow 1 listbox to chat to the other
      function Labels() {
      this.lab = new Array(0);
      this.dat = new Array(0);
      }
      Labels.prototype.addLabel = function(name, value) {
      this.lab.push(name);
      this.dat.push(value);
      };
      Labels.prototype.change = function(obj) {
      var i;
      obj.removeAll();
      for (i=0; i<this.dat.length; i++) {
      obj.addItem(this.lab , this.dat);
      }
      obj.setScrollPosition(0);
      };
      FlistBoxClass.prototype.changeLabels = function() {
      this.getValue().change(this.sub);
      };
      FlistBoxClass.prototype.setSubMenu = function(sub, label, x, y) {
      label.change(this);
      this.sub = sub;
      this.setChangeHandler("changeLabels", this);
      this.setSubIndex(x, y);
      };
      FlistBoxClass.prototype.setSubIndex = function(x, y) {
      this.setSelectedIndex(x);
      this.sub.setSelectedIndex(y);
      };
      //change what you like here to add your own artists and songs
      //just make sure the title of the song is the same as the name of the mp3
      //eg for myGreatSong.mp3 add the title as myGreatSong
      //the data being added to the listbox is for demonstration only as no use is made of it
      menu = new Labels();
      menu.addLabel("Dire Straits", submenu=new Labels());
      submenu.addLabel("Sultans of Swing", 1);
      submenu.addLabel("Money for Nothing", 2);
      submenu.addLabel("Romeo and Juliet", 3);
      submenu.addLabel("Telegraph Road", 4);
      submenu.addLabel("I Want my MTV", 4);
      menu.addLabel("Eagles", submenu=new Labels());
      submenu.addLabel("Desperado", 1);
      submenu.addLabel("Hotel California - Unplugged", 2);
      submenu.addLabel("Lying Eyes", 3);
      submenu.addLabel("New Kid In Town", 4);
      submenu.addLabel("On the Border - Already Gone", 5);
      submenu.addLabel("Take It To The Limit", 6);
      submenu.addLabel("Peaceful, Easy Feeling", 7);
      submenu.addLabel("Take it Easy", 8);
      submenu.addLabel("Tequila Sunrise", 9);
      menu.addLabel("The Beatles", submenu=new Labels());
      submenu.addLabel("Come Together", 1);
      submenu.addLabel("Here Comes the Sun", 2);
      submenu.addLabel("Hey Jude", 3);
      submenu.addLabel("Lady Madonna", 4);
      submenu.addLabel("Lucy In the Sky With Diamonds", 5);
      submenu.addLabel("Maxwell's Silver Hammer", 6);
      submenu.addLabel("Octopus's Garden", 7);
      submenu.addLabel("Revolution 1", 8);
      submenu.addLabel("While My Guitar Gently Weeps", 9);
      menu.addLabel("Bob Marley", submenu=new Labels());
      submenu.addLabel("No Woman No Cry", 1);
      submenu.addLabel("Jammin", 2);
      submenu.addLabel("Exodus", 3);
      menu.addLabel("Bob Dylan", submenu=new Labels());
      submenu.addLabel("Like A Rolling Stone", 1);
      submenu.addLabel("Mr Tamborine Man", 2);
      menu.addLabel("Rolling Stones", submenu=new Labels());
      submenu.addLabel("Wild Horses", 2);
      menu2 = new Labels();
      menu2.addLabel("Dire Straits", submenu=new Labels());
      submenu.addLabel("Sultans of Swing", 1);
      submenu.addLabel("Money for Nothing", 2);
      submenu.addLabel("Romeo and Juliet", 3);
      //formatting buttons and listboxes....change to suit
      aformat = new FStyleFormat();
      aformat.textSize = 12;
      aformat.textColor = 0xffff00;
      aformat.textBold = false;
      aformat.textUnderline = false;
      aformat.textFont = "Arial";
      aformat.face = 0x000000;
      aformat.arrow = 0xffffff;
      aformat.highlight = 0x0000ff;
      aformat.highlight3D = 0x0000ff;
      aformat.darkshadow = 0x0000ff;
      aformat.shadow = 0x0000ff;
      aformat.background = 0x123456;
      aformat.selection = 0xffffff;
      aformat.selectionUnfocused = 0xff0000;
      aformat.textSelected = 0x0000ff;
      aformat.applyChanges();
      aformat.addListener(playB, pause, loadB, loadBB, artists, titles);
      //titles list box handler
      titles.setChangeHandler("playsongs");
      function playsongs() {
      s.stop();
      delete s;
      playB.setEnabled(true);
      playB.setLabel("Play");
      pause.setLabel("Pause");
      pause.setEnabled(false);
      loadB.setEnabled(true);
      loadB2.setEnabled(true);
      loaded = true;
      paused = false;
      }
      //code for buttons
      loadB.onRelease = function() {
      artists.setSubMenu(titles, menu, 0, 0);
      };
      loadBB.onRelease = function() {
      artists.setSubMenu(titles, menu2, 0, 0);
      };
      playB.onRelease = function() {
      if (loaded) {
      theSong = path+titles.getSelectedItem().label+".mp3";
      s = new Sound(this);
      s.loadSound(theSong, true);
      s.setVolume(volSlide._x - 230);
      s.start(0,1);
      playB.setLabel("Stop");
      pause.setEnabled(true);
      } else {
      s.stop();
      pause.setEnabled(false);
      playB.setLabel("Start Again");
      }
      loaded = !loaded;
      };
      pause.onRelease = function() {
      if (!paused) {
      s.stop();
      playB.setEnabled(false);
      stopped = s.position/1000;
      this.setLabel("Continue");
      } else {
      this.setLabel("Pause");
      s.start(stopped,1);
      playB.setEnabled(true);
      }
      paused = !paused;
      };
      volSlide.onPress = function() {
      volSlide.startDrag(true, 242, 274, 342, 274);
      volSlide.onEnterFrame = function() {
      s.setVolume(volslide._x - 242);
      };
      };
      volSlide.onRollOut = volslide.onRelease = volslide.onReleaseOutside = function() {
      stopDrag();
      };
      panSlide.onPress = function() {
      panSlide.startDrag(true, 431, 274, 531, 274);
      panSlide.onEnterFrame = function() {
      s.setPan(panslide._x - 431);
      };
      };
      panSlide.onRollOut = panslide.onRelease = panslide.onReleaseOutside = function() {
      stopDrag();
      };