Hi everybody,
I just joined this forum like 1 week ago and i posted about making a listBox that would be used to play music … I need help with a little code in the listBox :
music = new Sound(this);
list.addItem(“Music”, music.attachSound(“barry”));
list.addItem(“Music1”, music.attachSound(“beegees”));
“music” is the name used for the play/stop button. I want that when i’m choosing like the “Music1” it plays the song named beegees … With this code, when i’m clicking play it’s playing the second one and even if i click on “Music” it’s still playing the second one … Could someone correct my code or tell me where i’m wrong … It would be really appreciated
Thanks,
~Francky683~
Btw if you can’t understand me plz tell me (sry i’m french and i can’t explain as well as you guys )
1) First, create a listbox and give it an instance name of myListBox.
2) Now create a textfield to display the loading progress. Set it to dynamic and give it an instance name of myTextField.
3) Place 2 buttons onstage. Set their instance names to play_btn and stop_btn
4) Time to create your textfile that will hold the song list. Lets say you have 3 mp3 files called:[list]**
[]metallica.mp3
[]beatles.mp3
[*]bee gees.mp3
**[/list]
Now open notepad and write the following:
music_list=metallica,beatles,bee gees&
5) Finally, the actionscript. Place this code on a frame:
my_sound = new Sound();
loadText = new LoadVars();
loadText.load("music_list.txt");
loadText.onLoad = function(success) {
if (success) {
var my_array = loadText.music_list.split(',').sort();
for (var i = 0; i<my_array.length; i++) {
myListBox.addItem(my_array*);
}
} else {
myListBox.addItem("Error loading contents!");
}
};
loadSong = function () {
var which = myListBox.getSelectedItem().label;
my_sound.loadSound(which+".mp3", false);
preload();
};
preload = function () {
this.createEmptyMovieClip("temp", 1000);
temp.onEnterFrame = function() {
var t = my_sound.getBytesTotal(), l = my_sound.getBytesLoaded();
if (t && !isNaN(t)) {
var percent = Math.floor(l*100/t);
if (percent == 100) {
myTextField.text = "Playing";
my_sound.start(0, 1);
this.removeMovieClip();
} else {
myTextField.text = percent+" %";
}
}
};
};
play_btn.onPress = loadSong;
stop_btn.onPress = function() {
my_sound.stop();
myTextField.text = "";
};
i’ve got another question … how can i customize the text displayed in myTextField ??? like displaying the songs title/artist and not the little “Playing” …
yea thx but that’s only a part of what i meant … could i customize what is written ??? not only the song title displayed in the listBox but anything else ???
Yes you can.
Heres one way:
Store 2 variables in the txt file; one for the song list and another for the captions
So your textfile should look like this:[AS]music_list=bee gees,metallica, beatles&captions=Bee Gees - I Started A Joke,Metallica - One, Beatles - Come Together&[/AS]And your code:[AS]my_sound = new Sound();
loadText = new LoadVars();
loadText.load(“music_list.txt”);
loadText.onLoad = function(success) {
if (success) {
var my_array = loadText.music_list.split(’,’);
caption_array = loadText.captions.split(’,’);
for (var i = 0; i<my_array.length; i++) {
myListBox.addItem(my_array*);
}
} else {
myListBox.addItem(“Error loading contents!”);
}
};
loadSong = function () {
var which = myListBox.getSelectedItem().label;
my_sound.loadSound(which+".mp3", false);
preload();
};
preload = function () {
this.createEmptyMovieClip(“temp”, 1000);
temp.onEnterFrame = function() {
var t = my_sound.getBytesTotal(), l = my_sound.getBytesLoaded();
if (t && !isNaN(t)) {
var percent = Math.floor(l*100/t);
if (l == t) {
myTextField.text = caption_array[myListBox.getSelectedIndex()];
my_sound.start(0, 1);
this.removeMovieClip();
} else {
myTextField.text = percent+" %";
}
}
};
};
play_btn.onPress = loadSong;
stop_btn.onPress = function() {
my_sound.stop();
myTextField.text = “”;
};
(Just a little question … is there a limit of variables to use in the text files ??? (cuz i’ll maybe add lyrics to the songs so i’ll just try, you did enough for mow :P))
Glad I could help;)
As for the limit of variables in text files, i really have no clue :cyclops:
Go ahead and try to add the lyricvs. If you get stuck, post here. Im sure someone will help you.