Triggering an setInterval manualy

Posted on 2011-05-12
Last Modified: 2013-11-11

I have a setInterval that runs in four seconds and can be paused with a play button. However, when it is unpaused I want the interval to run instantly rather than waiting another 4 seconds to run again.

Is there a way I can either:
Trigger the interval manually, with say, a function
Make the interval run instantly on the first run

Thanks, any help appreciated
Question by:andrewkhan
    1 Comment
    LVL 10

    Accepted Solution

    If you're using setInterval, the first parameter you have to pass to it is a function.
    Simply make sure that the function is not an anonymous one, and you can call the function at any time.

    Here's an example from

    function callback1() {
          trace("interval called");

    setInterval( callback1, 1000 );

    In the example, callback1 will be called every second, but you can call callback1 at any other time that you want.
    Make sure to call the function and then make the 4 second timer begin again when you're unpaused.

    Hope this helps.


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
    I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
    In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
    The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now