dcsimg
A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Pausing setInterval Timer?

  1. #1

    Pausing setInterval Timer?

    Is there a way to pause a setInterval timer, without clearing it?

    I have a timer set to, say 10000, while an audio clip plays, then it goes to the nextFrame.

    I want to add a pause and play button to stop and start the timer, as well as the audio. I can get the audio clip working fine, but not the timer.

    Is there a way to trace or read the value of it and then just reset the pause length to that value on the play button script?

    Thanks

  2. #2
    Banned NTD's Avatar
    Join Date
    Feb 2004
    Posts
    3,438
    Hi,

    It sounds as though you just need to record the current time in the counter when a button is pressed to stop it, then use that time amount when resetting the interval.

  3. #3
    Yes, that is exactly what I need to do, but how do I do that using setInterval?

    Here is the simple function in frame one of the movie:

    function pause(){
    play();
    clearInterval(_root.mytimer);
    }

    Here is the action on the frame where I have the pause:

    stop();
    _root.mytimer = setInterval(pause, 10000);

    What code do I add to my pause button to read the current value of the timer?

    Thanks.

  4. #4
    Senior Member k/smaert's Avatar
    Join Date
    Dec 2003
    Posts
    210
    you can't read the timer. you have to do smth like this:

    Code:
    var keeptrack = 0;
    
    function tracker(){
      keeptrack += 1000;
    }
    
    
    function pause(){
      play();
      clearInterval(int_id);
      //here you can read the value of keeptrack and do some math to create a new setintervall
    
    
    }
    
    var int_id = setInterval(tracker, 1000);

    hope this helps

  5. #5
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    do you want a clock like timer where you can display the time of the sound playing, and at a certain time another action will happen, like change frames?
    If you don't think you're going to like the answer, then don't ask the question.

  6. #6
    Banned NTD's Avatar
    Join Date
    Feb 2004
    Posts
    3,438
    Hi,

    After a quick try, while you cant read the actual time in the setInterval method, you can add a timer to the function with getTimer.....something like.....

    code:

    myTime = 10000;
    function pause() {
    testTime = getTimer()/1000;
    trace("Time trace = "+testTime+ " seconds");
    play();
    if (testTime>=myTime/1000) {
    clearInterval(_root.mytimer);
    trace("interval cleared");
    }
    }
    _root.mytimer = setInterval(pause, myTime);
    //Mouse down event to test
    _root.onMouseDown = function() {
    //trace current time elapsed
    pause();
    }


  7. #7
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    i don't understand what it is the person is timing, is it the sound, or the movie?
    If you don't think you're going to like the answer, then don't ask the question.

  8. #8
    Banned NTD's Avatar
    Join Date
    Feb 2004
    Posts
    3,438
    I'm not exactly certain of that myself. I'm just shooting in the dark with a setInterval demo using getTimer to trace time elapsed. If your using this with sound, it would be a matter of using a sound object and duration and position. It sounds as though the time is kept seperatly with setInterval and the sound is handled elsewhere, either in a sound object or possibly a movieclip with the sound imported directly.

  9. #9
    Thanks for the assistance.

    What I am timing is the length of the audio clip (wav file).

    So I set the timer to the length of the clip, the movie stops until it's over and then plays to the next frame. Then I have another clip and another timer there...

    I'll try the suggestions here.

    Appreciate the help.

  10. #10
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    check out this sample, see if it's what you want, or something like it
    Please scan it for viruses before opening, because anything i download from here is always scanned first before opening, just as a precaution
    Download
    I imported mp3 files instead of wav files, it works regardless, just make sure you give linkage names to the files. Hope it helps
    If you don't think you're going to like the answer, then don't ask the question.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center