Passing arguments to functions

hi,
i have a music jukebox, with ten buttons.
in the first keyframe, of the main timeline, a put a function that will be used for every button to load the mp3 to play.
The problem, is that when i pass the arguments on each button to call the function, the “filme” and “som” arguments are lost.

here is the function:

function carregaSom(filme, som, url, msg1, msg2, tempoComeco){
_root.createEmptyMovieClip(filme, 1)
som=new Sound(filme);
som.loadSound(url, false);
som.onLoad=function(success){
if(success){
textoDownload.text=msg1;
som.start(tempoComeco, 9999);
}
else { textoDownload.text=msg2;
clearInterval(percentagemDownload);
}
}
percentagemDownload = setInterval(verificarDownload(), 50);
}//close function carregaSom()

//this function is to determine the percentage of the downloaded sound and change the msgbox ‘textoDownload’
function verificarDownload(){
var obj = som;
var loadedBytes = obj.getBytesLoaded();
var totalBytes = obj.getBytesTotal();
calculoPercentagem = Math.floor((loadedBytes/totalBytes)*100);
percentagem = "A carregar: " + calculoPercentagem + “%”;
textoDownload.text=percentagem;
if (loadeBytes>=totalByttes){
clearInterval(percentagemDownload);
}//close if
} //close function verificarDownload()

In each button i put this code:

on(release){
//Prepare the parameters to be passed to function
url=“http://www.myserver.org/flash/som/som2.mp3”;
msg1=“A tocar Som 2”;
msg2=“Erro no som 2”
tempoComeco=“0.1”;

//call the function
carregaSom(mcSomLoop2, som2, url, msg1, msg2, tempoComeco);
_root.som=“som2”; //set new value to a root variable, so i always know what music is playing.
}

The problem is, when a say here that the first and second parameter of the function are ‘mcSomLoop2’ and ‘som2’, are to be passed to the function that way, to create a mC and a sound object with that names, so i can call them in the future to change volume, and to determine the percentage of downloaded sound.

When the function runs, calls the second function with setInterval, verificarDownload(), that needs to know what sound is downloading. But if a make a trace(totalBytes);, i get ‘undefined’, so i never get the real sound ID, so i can maipulate it (setVolume, setPan).

How do i pass the arguments to the function so the function create a really sound Object with an ID, so i can call it later.
Anyway, with this code, all buttons call the respective sound and start playing it. but, the messagem of the percentage loaded returns “Loading: NaN%”… and i will never be able to edit or delete the sound when i want.

best regards
álvaro

Hiya!

Here’s what you have to do. When you say:

carregaSom(mcSomLoop2, som2, url, msg1, msg2, tempoComeco);

what you are really doing is sending the variables mcSomLoop2 and som2. You want to send the literal strings “mcSomLoop2” and “som2”. So all you do is say this:

carregaSom("mcSomLoop2", "som2", url, msg1, msg2, tempoComeco);

And that’s it!

:slight_smile:

-Al