[Javascript] setTimout problems (again)

Chris Basken chriz at basken.com
Thu Jul 11 10:03:54 CDT 2002


Why is setTimout such a pain to use?  I have a function that I want to call
itself every so often:

function
putLayer(layerName,timeOutPause,Xinc,Yinc,toX,toY,moveSteps,currentStep) {
 document.all[layerName].style.left =
Math.round(parseInt(document.all[layerName].style.left) + Xinc);
 document.all[layerName].style.top  =
Math.round(parseInt(document.all[layerName].style.top) + Yinc);
 currentStep++;

 if (currentStep <= moveSteps) {

setTimeout("putLayer(layerName,timeOutPause,Xinc,Yinc,toX,toY,moveSteps,curr
entStep)",timeOutPause);
 }

}

This function works once (it's called from elsewhere; a setup function that
defines those arguments initially), then warns me that "layerName is not
defined".  I've tried it with the function call in quotes, not quoted,
quoted but with the arguments not in quotes ("putLayer(" + layerName + "," +
timeoutPause... etc), and with the arguments following the pause argument
(which is what Netscape's DevEdge page says to do).  Nothing works.  Is this
function just defunct or something?  Or am I blind as a bat and there's some
silly error in my function causing it to frank out?

Agh!





More information about the Javascript mailing list