Jump to content


ListBox Component SelecteItem Help!


  • You cannot reply to this topic
4 replies to this topic

#1 gostmn26

    Young Padawan

  • Members
  • Pip
  • 12 posts
  • Gender:Male
  • Location:14560

Posted 28 January 2007 - 02:17 PM

I am pretty new to Flash but have some C++ coding background and have been able to figure out most of my program.

The problem I am having is that when the selectedItem is clicked on it displays an error and keeps playing the current song. What do I need to do in order to get it to play the selectedItem

I have included the codfe here as you can see as well as uploaded the file to look at. I could use any help on cleaning it up as well as criticism on it as it's my first flash project. I am also trying to figure out how i call the initbars function so it only plays if music is and stops when it does.

Thanks

stop();
title_txt.autoSize = "left";
timeDisplay_txt.autoSize = "left";
toolTip._visible = false;
var amountLoaded:Number;
var duration:Number;

//Open XML and put data into array
var playlist:XML = new XML();
playlist.ignoreWhite = true;
playlist.onLoad = function(success) {
 if (success) {
  _global.songname = [];
  _global.songband = [];
  _global.songfile = [];
  for (var i = 0; i<playlist.firstChild.childNodes.length; i++) {
  _global.songname[i] = playlist.firstChild.childNodes[i].attributes.name;
  _global.songband[i] = playlist.firstChild.childNodes[i].attributes.band;
  _global.songfile[i] = playlist.firstChild.childNodes[i].attributes.file;
  mp3List.addItem(songband[i]+" ("+songname[i]+")");
  }
 }
 //Start and load movieclip
 _root.createEmptyMovieClip("sound_mc", 1);
 _global.song_nr = 0;
 _root.sound_mc.songStarter(songfile[song_nr]);
 // ListBox component commands
 mp3List.selectedIndex = 0;
 mp3List.hScrollPolicy = "on";
 mp3List.maxHPosition = 150;
 mp3list.selectable = true;
 // Change playing song when tracks are clicked
 var mp3Change:Object = new Object();
 mp3Change.change = function() {
     clearInterval(timeInterval);
  _root.timeDisplay_txt.text = "00:00/00:00";

 };
 mp3list.addEventListener("change", mp3Change);
};
//Timer Function
function timer(sound_obj) {
 time = sound_obj.position/1000;
 min = Math.floor(time/60);
 min = (min<10) ? "0"+min : min;
 sec = Math.floor(time%60);
 sec = (sec<10) ? "0"+sec : sec;
 timeDisplay_txt.text = min+":"+sec+"/"+totalDuration;
}
//For time left playing
function duration (){
 timed = _root.sound_mc.sound_obj.duration/1000;
 mind = Math.floor(timed/60);
 mind = (mind<10) ? "0"+mind : mind;
 secd = Math.floor(timed%60);
 secd = (secd<10) ? "0"+secd : secd;
 totalDuration = mind+":"+secd;
}
//Song starter
MovieClip.prototype.songStarter = function(file) {
 if (this.sound_obj) {
  this.sound_obj.stop();
  delete this.sound_obj;
 }
 this.sound_obj = new Sound(this);
 this.sound_obj.loadSound(file, true);
 this.sound_obj.setVolume(90);
 this.onEnterFrame = function() {
  if (this.sound_obj.position>0) {
   delete this.onEnterFrame;
   timeInterval = setInterval(timer, 1000, this.sound_obj);
   track = this.sound_obj.id3.songname;
   artist = this.sound_obj.id3.artist;
   this._parent.title_txt.text =artist+" - "+track;
  } else {
   this._parent.title_txt.text = "loading...";
  }

 };   
 this.sound_obj.onSoundComplete = function() {
  clearInterval(timeInterval);
  _root.timeDisplay_txt.text = "00:00/00:00";
  (song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
  (mp3list.selectedIndex == songfile.length-1) ? mp3list.selectedIndex=0 : mp3list.selectedIndex++;

 };
 
 this._parent.volume1.dragger.onPress = function() {
  startDrag(this, true, 0, this._y, this._parent.volBG._width, this._y);
  _root.toolTip._visible = true;
  setInterval(draggableTip,100);
  function draggableTip(){
   _root.toolTip._x = _root._xmouse;
  }
  this.onEnterFrame = function() {
   var p = (this._x/this._parent.volBG._width)*100;
   this._parent._parent.sound_mc.sound_obj.setVolume(p);
   
  };
 };
 this._parent.volume1.dragger.onRelease = function() {
  delete this.onEnterFrame;
  stopDrag();
  
 };
 this._parent.volume1.dragger.onReleaseOutside = function() {
  _root.toolTip._visible = false;
  stopDrag();
  
 };
};
//Button Controls
btn_play.onRelease = function() {
    if (pause == true){ // no comment....
        this._parent.sound_mc.sound_obj.start(posiP) // start sound from the previously saved position
    }
    else {
     clearInterval(timeInterval);
     _root.timeDisplay_txt.text = "00:00";
     this._parent.sound_mc.songStarter(songfile[song_nr], songname[song_nr]);
    }
};
btn_pause.onRelease = function() { //pause button function
    this._parent.sound_mc.sound_obj.stop(); //stop the current sound
    posiP = _root.sound_mc.sound_obj.position / 1000; // save the current position in a new variable and divide by 1000 (ms -> sec)
    pause = true;//set the variable pause to true
}
btn_stop.onRelease = function() {
 clearInterval(timeInterval);
 _root.timeDisplay_txt.text = "00:00/00:00";
 pause = false;
 this._parent.sound_mc.sound_obj.stop();
};
btn_fw.onRelease = function() {
 clearInterval(timeInterval);
 _root.timeDisplay_txt.text = "00:00/00:00";
 (song_nr == songfile.length-1) ? _global.song_nr=0 : _global.song_nr++;
 (mp3list.selectedIndex == songfile.length-1) ? mp3list.selectedIndex=0 : mp3list.selectedIndex++;
 _root.sound_mc.songStarter(songfile[song_nr]);
};
btn_rev.onRelease = function() {
 clearInterval(timeInterval);
 _root.timeDisplay_txt.text = "00:00/00:00";
 (song_nr == 0) ? _global.song_nr=songfile.length-1 : _global.song_nr--;
 _root.sound_mc.songStarter(songfile[song_nr]);
 (mp3list.selectedIndex==0)? mp3list.selectedIndex=songfile.length-1 : mp3list.selectedIndex--;
 
};
//Declare playlist
playlist.load("[url="http://www.fileden.com/files/2007/1/1/579674/Dizzie/mp3playlist.xml"]http://www.fileden.com/files/2007/1/1/5796...mp3playlist.xml[/url]");
setInterval(duration,100);
setInterval(soundStatus,100);


// Project: make a fake equalizer like movie clip for use when music is playing in Flash
// project has lines and toppers, each labeled linex & topperx where x is 1 to 20.
// the lines make up the tall parts of the equalizer, the toppers are just a line placeholder 
// for the max value of the lines 
// define initial arrays 

barboty=new Array(); //holds bottom of each line's _y registration point 
randheight=new Array(); //holds randomly generated height of line 
toppery=new Array(); //holds _y registration point of topper 
decfraction=new Array(); //holds the fraction of random height of line that will be used to decrement the line's height 
numbars=40; //defines number of lines 
maxheight=115; //defines max height of line 
minheight=1; //defines min height of line 
gap=2; //defines distance between top of line and topper 
topperdrop=.075; //defines value to decrement _y value of topper 
numsteps=7; //defines number of steps to decrement height of line 
  
// this function sets values for the heights of each line in the equalizer 
function initbars() { 
   for (i=1;i<_root.numbars+1;i+=1) { 
      barboty[i]=eval("_root.line"+i)._y; 
      randheight[i]=Math.random()*maxheight; 
      toppery[i]=barboty[i]-randheight[i]-gap; 
      decfraction[i]=randheight[i]/(_root.numsteps); 
  
      // set initial line height and position of topper 
      setProperty(eval("_root.line"+i),_height,_root.randheight[i]+_root.minheight); 
      setProperty(eval("_root.topper"+i),_y,barboty[i]-randheight[i]-_root.gap-_root.minheight); 
   } 
} 
 
// this function will get executed at the playing frame rate of the movie, even if the movie is stopped 
_root.onEnterFrame = function() { 
  for (j=1;j<_root.numbars+1;j+=1) { //set height of each line for each j in numbars 
    setProperty(eval("_root.line"+j),_height,_root.randheight[j]); 
     if (_root.randheight[j]<=_root.minheight) { // if the line height is less than the min, then:
                                                // set line height to the min then redo the line heights etc 
       
setProperty(eval("_root.line"+j),_height,_root.minheight); 
      _root.initbars(); // the entire function initbars could be placed here if you like rather than being called. 
    } else { //if not too short, decrement height of lines and position of topper 
      _root.randheight[j]=_root.randheight[j]-_root.decfraction[j]; 
      setProperty(eval("_root.topper"+j),_y,eval("_root.topper"+j)._y+_root.topperdrop); 
    } 
  } 
}


#2 gostmn26

    Young Padawan

  • Members
  • Pip
  • 12 posts
  • Gender:Male
  • Location:14560

Posted 31 January 2007 - 09:12 PM

Ok I see no one wants to give me a hand.

First I have to say thanks to FunkySoul for a great tutorial and the best and easiest to understand that I have used to create a MP3 player and I have tried quite a few different ones and they aren't as easily to adapt to personal needs.

I did figure out the listbox and have it working and put a working basic version of what I made on my girlfiends myspace http://www.myspace.com/purpleluster21 . I will be putting a version on my page soon that looks like a dog tag. I could still use a little help with cleaning up the code and with the equilizer. I got it to where it will start only after the song starts playing but don't know how to stop or pause it with the music.

Edited by gostmn26, 31 January 2007 - 09:13 PM.


#3 Ben

    P2L Jedi Master

  • Publishing Betazoids
  • PipPipPipPip
  • 1,366 posts
  • Gender:Male
  • Location:VIC, Australia

Posted 01 February 2007 - 12:21 AM

I would've helped but I didn't made the tutorial you read, and I don't usually deal with components (I just make my own). But, I'm glad you figured it out :)

#4 gostmn26

    Young Padawan

  • Members
  • Pip
  • 12 posts
  • Gender:Male
  • Location:14560

Posted 01 February 2007 - 07:21 AM

View PostBen, on Feb 1 2007, 12:21 AM, said:

I would've helped but I didn't made the tutorial you read, and I don't usually deal with components (I just make my own). But, I'm glad you figured it out :tiphat:


Yea well eventually the more I learn I will be making my own components as I have only been using flash for about a week or two now. From what I see I don't like the premade components as they are pretty large and put too much unneccessary information into the flash document.

Where would be a good place to find info on creating my on components? I have been looking on adobe's site but I have a hard time learning from reading and need to be shown how it orks instead. This is my only major default. I guess I can look into wether Flash is an elective for the classes I am gonna be starting on University of Phoenix online in a couple weeks to finish my degree for networking w/cisco.

As far as my equilizer goes I made 2 compiled clips. One is the bar and the other is the top, now how would I combine the 2 into one and make them work the same. Are these compiled clips considered components?

#5 Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 01 February 2007 - 10:24 AM

View Postgostmn26, on Feb 1 2007, 07:21 AM, said:

From what I see I don't like the premade components as they are pretty large and put too much unneccessary information into the flash document.

Smart for a flash newbie :tiphat: Only use the components that come with flash if you have to...you're right, they are huge, and if you make your own, they'll generally work better, and be way smaller.

As far as learning without reading....fire up google and look for some video tutorials. People make them...theyre usually 30 mins long or so, but you get to see what they do while its explained to you. Its pretty decent stuff.

Edited by Pax, 01 February 2007 - 10:26 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users