Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Location
    Port Huron, MI, U.S.A.
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Timeout only happens once

    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:

    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?
    Last edited by Bobo; 08-15-2004 at 05:57 PM.
    Oh, was I supposed to put something here? ........

  • #2
    Regular Coder
    Join Date
    Jan 2004
    Posts
    185
    Thanks
    2
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Bobo
    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:

    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?
    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).

  • #3
    Regular Coder
    Join Date
    Jan 2004
    Location
    Port Huron, MI, U.S.A.
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Oh, was I supposed to put something here? ........

  • #4
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Code:
    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
    Last edited by dumpfi; 08-15-2004 at 07:07 PM.

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    You have no timer within the function
    Last edited by Mr J; 08-16-2004 at 03:53 PM.
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #6
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    window.setInterval should do the job.

    dumpfi

  • #7
    Regular Coder
    Join Date
    Jan 2004
    Location
    Port Huron, MI, U.S.A.
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sweeeet! 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.
    Oh, was I supposed to put something here? ........


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •