Click to See Complete Forum and Search --> : settimeout error fix.....


Code One
09-12-2003, 11:18 AM
<script>

var syllables = new Array( "ay", "bay", "bih" );
var phrase = new Array;
var typed = " ";

document.onkeypress = function ( evt ) {

var c = document.layers ? evt.which
: document.all ? event.keyCode
: evt.which;


typed += String.fromCharCode( c );

for( i=syllables.length; i > -1 ; i-- ) {

if ( typed.indexOf( syllables[i]) != -1 ) {

phrase.push(syllables[i]);
typed = " ";
}
}
}


function playPhrase() {
if( phrase.length > 0 )
//alert(phrase.join( " - "));
phrase.reverse();
playSound();
}

function playSound() {
soundfile = document.getElementById(phrase.pop());
soundfile.play()
if( phrase.length > 0 ) { playSound() }

{
setTimeout("playSound();", 1500);
}
}

</script>

============================================================
Please notice above the scripts which are bold. I believe these two are at fault for the error. It seems shortly after you have typed your input and have pushed play the document shows an error. So I assume it is due to the settimeout. Please feel free to explore the rest of this script, for the error may lye some where in the non-bold script as well.

All help is appreciated.

Code One

zachzach
09-14-2003, 05:10 PM
try:

function playPhrase() {
if(phrase.length > 0) {
//alert(phrase.join( " - "));
phrase.reverse();
playSound();
}
}

function playSound() {
soundfile = document.getElementById(phrase.pop());
soundfile.play()
if( phrase.length > 0 ) {
playSound()
}
setTimeout("playSound();", 1500);
}
</script>

Code One
09-14-2003, 06:23 PM
thanks for posting! I was actually able to figure it out a little bit ago and it is alot like your code. But, I appreciate your help anyway.

Thanks just the same,

Code One