Code One
06-18-2003, 11:45 PM
Hello I am trying to make a javascript piano and I have a script which allows the user to click a sound which is in my example a text link, anyway the text link (which is linked to a sound) is saved in memory by order of click. Lets say there are three keys, the user presses the 2 key first, then the 1 key second, and finally he pushes the 3 key last. Ok? Now once the user has finished clicking the text links (keys) and then pushes the play button [review script] the sounds are played all at one time. I am looking for a script that allows for the sounds to play one by one without the overlapping part. I would like for the user to still push the play button but instead of the all at once playback I would like for the sounds to play for this example (2,1,3, keys), in that order [2-1-3].
*note the order of the sounds being played back is determined by the order of clicks from the user.
Heres the script to add the delay function to:
==========================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Sound Test</title>
<script language="JavaScript">
var playlist = new Array();
var x = -1;
function add(sound){
x=x+1;
playlist[x] = sound;
}//ends add()
function play_it(){
for (i = 0; i < playlist.length; i++){
document[playlist[i]].Play();
}//ends FOR
}//ends play_it()
function reset_list(){
var playlist = new Array();
var x = -1;
}
</script>
</head>
<body>
<a href="javascript: add('gong')">Gong Sound</a><br><br>
<a href="javascript: add('foghorn')">Fog Horn</a><br><br>
<a href="javascript: add('cuckoo')">Cuckoo Clock</a><br><br>
<form>
<input type="button" value="Play" onClick="play_it()">
<input type="button" value="Reset" onClick="reset_list()">
</form>
<!-- Sound Embeds -->
<embed name="gong" src="gong.wav" autostart="false" hidden="true" loop="false"></embed>
<embed name="foghorn" src="foghorn.wav" autostart="false" hidden="true" loop="false"></embed>
<embed name="cuckoo" src="cuckoo.wav" autostart="false" hidden="true" loop="false"></embed>
</body>
</html>
===========================================
I think the reset function is wrong too, I am a total newbie to jscript, so anyone who feels like helping me would be very much appreciated.
Thanks in advance,
Code One
*note the order of the sounds being played back is determined by the order of clicks from the user.
Heres the script to add the delay function to:
==========================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Sound Test</title>
<script language="JavaScript">
var playlist = new Array();
var x = -1;
function add(sound){
x=x+1;
playlist[x] = sound;
}//ends add()
function play_it(){
for (i = 0; i < playlist.length; i++){
document[playlist[i]].Play();
}//ends FOR
}//ends play_it()
function reset_list(){
var playlist = new Array();
var x = -1;
}
</script>
</head>
<body>
<a href="javascript: add('gong')">Gong Sound</a><br><br>
<a href="javascript: add('foghorn')">Fog Horn</a><br><br>
<a href="javascript: add('cuckoo')">Cuckoo Clock</a><br><br>
<form>
<input type="button" value="Play" onClick="play_it()">
<input type="button" value="Reset" onClick="reset_list()">
</form>
<!-- Sound Embeds -->
<embed name="gong" src="gong.wav" autostart="false" hidden="true" loop="false"></embed>
<embed name="foghorn" src="foghorn.wav" autostart="false" hidden="true" loop="false"></embed>
<embed name="cuckoo" src="cuckoo.wav" autostart="false" hidden="true" loop="false"></embed>
</body>
</html>
===========================================
I think the reset function is wrong too, I am a total newbie to jscript, so anyone who feels like helping me would be very much appreciated.
Thanks in advance,
Code One