Q on Loading techniques tutorial http://www.kirupa.com/developer/mx/loading.asp

Well i was looking over

http://www.kirupa.com/developer/mx/loading.asp

And i got pretty stumped over when loading a mp3

I have 5 layers
and a mp3 named chillbeat.mp3

do i create a 6th layer for the code and just put it there???

and if i have a button to play it where would i put this

mySound = new Sound();
mySound.loadSound(“music.mp3”,true);

is that just the WHOLE CODE for that load mp3 process??

Any takers?

there is source files to download there , isent there?

you need to have the mp3 in the folder where you created the fla.

This is because your loading the mp3 dynamically.

the first part of the code is setting a variable so this generally goes into the first frame on the timeline



mySound = new Sound();


To make this method work as a button, you have to put the following code on the button



mySound.loadSound("music.mp3",true);


in our case my song is called ‘rain’

so



mySound.loadSound("rain",true);


hope this helps :slight_smile:

sorry here is the file. :smirk:

:beam: :beam: :beam: kickass soulty thanks a lot man!! you have saved me headaches of trying to figure out code! The thing is i have crazy ideas and just putting them together is hard and than comes the coding!

no worries dude, glad i could help. :beam:

Ok i got everything working with multiple songs at the same type

mySound = new Sound();
mySound1 = new Sound();

1st button

on (release) {
mySound.loadSound(“rain.mp3”, true);
}

2nd button

on (release) {
mySound1.loadSound(“red.mp3”, true);
}

Well lets say i want to have a pause button how would i do that?? I tried

on (press) {
if (playing==true) {
_root.mySound1.stop(“mySound1”);
_root.mySound.stop(“mySound”)
playing=false;

}
}

actually i found the answer to my own question here it is for people who are following!

Button 1

on(press) {
if (playing!=true) {
if (playing=true);
soundIsLoaded=1
mySoundObject1=new Sound();
mySoundObject1.setVolume(55);
mySoundObject1.loadSound(“rain.mp3”,true) //streaming
}
_root.mySoundObject1.onSoundComplete=function()
{playing=false;}
}

Button 2

on(press) {
if (playing!=true) {
if (playing=true);
soundIsLoaded=1
mySoundObject=new Sound();
mySoundObject.setVolume(55);
mySoundObject.loadSound(“red.mp3”,true) //streaming
}
_root.mySoundObject.onSoundComplete=function()
{playing=false;}
}

Stop Button

on(press) {
if (playing==true) {
playing=false;
mySound.stop()
mySound1.stop()
}
}

       Now what would i do if i just wanted to have ONE BUTTON just like on the cd player whereu have one button that advances to the next song and the other one that goesk back the the last song!

good to hear you got it all working, for the next and previous buttons you are trying maybe you can use a array, so you can list the mp3’s in this array. and with some code, have the button increment along the array each time its clicked,

I don’t really know how to use array’s, but its worth a look at.

i would also like to know how to do this, (Bump , as people would say)

:beam:

try this:


songArray= ["rain.mp3", "song2.mp3", "song3.mp3"];
songNum=0; //first position of array = 0

function loadNext(){
songNum+=1 %songArray.length;
//increments songNum, mods arrayLength so that it will
//return back to 0 after array length is exceeded
myName=songArray[songNum];
mySound.loadSound(myName, true);
} 

-mojo

Hey Soulty just liked to say thanks for the help you gave me , it really made me go nuts and crazy about the code , searching and everything!

Heres another question.

         I have the website and in the beginning i have preloader but the song i want to put is quite big so i want when the preloader is done loading that it would start streaming the music. How would i be able to do so?

oh man totally mind blank, i gotta go 2, ill try when i get back,

by the way you should thank mojoNYC for that array code, i didnt really have nothing to do with it, :smirk: :wink:

maybe he can help you with your question
:smirk:

best of luck:crazy:

I havent really tested out the array code but thanks mojo! can you help me with my other question?

About your array code , i put that on a button correct?? And one more thing

songArray= ["rain.mp3", "song2.mp3", "song3.mp3"];
songNum=0; //first position of array = 0

function loadNext(){
songNum+=1 %songArray.length

does that mean that if i have it in the same directory it will stream the music?

put the function and new array code on your main timeline

add the function call to your button:
on(release){
_root.loadNext();
}

afa streaming the first song/sound, put your new Sound() command inside the main movie frame, or wherever the preloader goes after its done–this way, the user can see the content, and the sound object will load the sound in the background…
-mojo

Hey

what line are you talking about??

 Sound()  

What else do i but lets say the song name is dum.mp3 how would i do that???

Got kinda confused.

put this on the root level of your main movie:


//set array of mp3 names
songArray=_["dum.mp3",_"song2.mp3",_"song3.mp3"];
//track position in array
songNum=0;_//first position of array = 0
//create dynamic var referencing song name in array list
myName=songArray[songNum];
mySound= new Sound(myName, true);

function_loadNext(){
songNum+=1_%songArray.length
myName=songArray[songNum];
mySound = new Sound(myName, true);
mySound.play();

then you can call my sound anytime you want to start

put this code on your button:


on(release){
_root.loadNext();

basically what your’e doing here is creating an array and function on the root level, and then calling the function from your button–make sense?
-m

This is what i got

Scene=Scene 1, Layer=Actions, Frame=1: Line 2: ']' expected
     songArray=_["reg.mp3",_"red.mp3",_"bud.mp3"];

Scene=Scene 1, Layer=Layer 6, Frame=1: Line 1: Statement block must be terminated by '}'
     on(release){

Scene=Scene 1, Layer=Layer 6, Frame=1: Line 2: Syntax error.
     _root.loadNext();


I got the middle one :slight_smile: that was the easiest error , but i dont know what to do about the other errors

oops, my code got a little mangled–those underscores shouldn’t be in there, plus i wrote some of it wrong (i didn’t have flash handy when i wrote it:blush: )
anyway, i fixed it up and attached a movie w. the code and a button–this will hopefully help you get it going again…
cheers,
-mojo