Click to See Complete Forum and Search --> : Help with outputs.
Nevermore
02-15-2003, 04:20 AM
I have used this code to try and play sounds with javascript, one after another, from a text area, in which you can type numbers. I thought that it would make them play one after another, with a 1 second gap. However, the first one plays fine, then all of the others play at the same time - not quite what I wanted!
function playLoaded() {
toPlay = document.getElementById("code").value;
// Gets individual Notes
notes = toPlay.split(" ");
// Plays notes
if (n < notes.length) {
v = notes[n];
n++;
window.setTimeout("playLoaded();",1000);
document.embeds[v].play();
}
}
Nevermore
02-15-2003, 10:21 AM
All of the sounds are one second long, and are just piano notes, so I didn't think itnwould be that complex. Since I know the length of each sound, could it be done?
Dan Drillich
02-15-2003, 10:29 AM
I think the following can help. The alerts show up one second apart -
<script>
var notes = new Object();
notes.length = 3;
var n = 0;
function bringAlert() {
alert(n);
n++;
if (n<notes.length) {
window.setTimeout("callSch()",1000);
}
}
function callSch() {
if (n < notes.length) {
bringAlert();
}
}
callSch();
</script>
Nevermore
02-15-2003, 10:34 AM
Did you preload the sounds?
I embedded them - is that right? They did play, just at the wrong times.
Nevermore
02-15-2003, 10:51 AM
The sounds played when I clicked links to them, and played instantly. It was just when I tried to call them one by one with javascript
Nevermore
02-15-2003, 11:00 AM
If you go here (http://www32.brinkster.com/jjscripts/musicstation1.htm#) then you should be able to play the piano by clicking. You should also be able to click generate code, which will make the 'code' for the tune. It's when you press load that it doesnt work. It plays the first note as it should, then all the others at the same time.
Nevermore
02-15-2003, 11:45 AM
IE 6 , windows 98SE
Nevermore
02-15-2003, 11:51 AM
So am I - but I can't find the source of them.
Nevermore
02-15-2003, 02:02 PM
Thank you VERY VERY VERY much. That must have taken you a long time, and I am very grateful. incidentally, do you have any general tips on how to become a good JavScripter?