...

View Full Version : Timeout only happens once



Bobo
08-15-2004, 03:46 AM
I have a simple adding script that is supposed to create a moving wave effect. However, the "setTimeout" timer I'm using will only call the function one time. setInterval does the same thing. This is the code:


<script language="JavaScript">
<!--hide
var D=new Date(),Time,M,S,H,TR=null,Phase=0,Q;
//.......

function Wave() {
Phase+=1;
/////////////////////////////////////////////
if (Phase>=1000) {Phase=0}
else {Phase+=0}
///////////////////////////////////////////////
window.document.getElementById("D").style.filter="glow(color=orange,strength=2) dropshadow(color=navy,positive='true',offx=1.5,offy=1.5) progID:DXImageTransform.Microsoft.wave(freq=4,phase="+Phase+",lightStrength=97,strength=7,add='true')";
window.status="Phase:"+Phase+",Q:"+Q+TR;
}




TR=window.setTimeout("Wave()",100)


//-->
</script>

Anyone know why the timer only calls once? :confused:

subhailc
08-15-2004, 07:27 AM
I have a simple adding script that is supposed to create a moving wave effect. However, the "setTimeout" timer I'm using will only call the function one time. setInterval does the same thing. This is the code:


<script language="JavaScript">
<!--hide
var D=new Date(),Time,M,S,H,TR=null,Phase=0,Q;
//.......

function Wave() {
Phase=1;
/////////////////////////////////////////////
if (Phase>=1000) {Phase=0}
else {Phase+=1}
///////////////////////////////////////////////
window.document.getElementById("D").style.filter="glow(color=orange,strength=2) dropshadow(color=navy,positive='true',offx=1.5,offy=1.5) progID:DXImageTransform.Microsoft.wave(freq=4,phase="+Phase+",lightStrength=97,strength=7,add='true')";
window.status="Phase:"+Phase+",Q:"+Q+TR;
}




window.setTimeout("Wave()",100)


//-->
</script>

Anyone know why the timer only calls once? :confused:
the var was never established, change += (which adds to an extant entity) to = (which assigns a value), and the operator to increment the phase var was recieving += 0, which doesn't do anything, so change that to += 1 (or more).

Bobo
08-15-2004, 05:56 PM
Actually, Phase was established as 0 outside of any functions, as you can see at the top of the code I posted. Also, if I use what you suggested, then Phase would always be at 2 because you're saying Phase=1+1. I've checked and confirmed that it actually is the timer. I have the script set so that, in the status bar, the timer var shows up (BTW, i forgot to put TR= in front of the timer in the posted code) and if the timer was ticking, the number in the statusbar where "TR" is would change (I've tried that before w/ other scripts and a timer will show up as a long # that goes up each time the timer ticks.)

Anyway, any other ideas? I still can't pinpoint the problem. :confused:

dumpfi
08-15-2004, 07:05 PM
var TR=null,Phase=0,Q=0; // don't know for what you needed the other vars

function Wave() {
Phase = (Phase > 999) ? 0 : Phase + 1;
window.document.getElementById("D").style.filter="progid:DXImageTransform.Microsoft.Glow(color='orange',strength=2) progid:DXImageTransform.Microsoft.DropShadow(color='navy',positive='true',offx=1.5,offy=1.5) progid:DXImageTransform.Microsoft.wave(freq=4,phase="+Phase+",lightStrength=97,strength=7,add='true')";
window.status="Phase:"+Phase+",Q:"+Q+TR;
}
TR = window.setInterval("Wave()",100);dumpfi

Mr J
08-16-2004, 03:48 PM
You have no timer within the function

dumpfi
08-16-2004, 05:41 PM
window.setInterval should do the job. ;)

dumpfi

Bobo
08-16-2004, 06:08 PM
Sweeeet! :D Just one question, though. Why didn't setInterval call the function like this:
1sec:call
nextSec: call call
nextSec:call call call?

I guess what I mean is why is interval acting like timeout in this case? This is really confusing. Interval did solve the problem, though, and I thank you. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum