A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: clear ALL Intervals ?

  1. #1
    Senior Member fantasio's Avatar
    Join Date
    May 2000
    Location
    at the progress bar
    Posts
    409

    clear ALL Intervals ?

    hi there,

    i 'd like to know if there is a way to clear all Intervals in a movie with one command...

    in my current project I use setInterval()
    very often in different clips and though i cleanly put the corresponding clearInterval() commands in the script I realized, that on slow computers some of them don't get stopped...
    which puts more weight on the CPU and sometimes slows down the comp very much.

    is there a fix ?


    tia

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    you could name them interval1, interval2,..., intervaln

    and then:
    trigger this:
    for (i=1; i<=n; i++) {
    clearInterval(_root["interval"+i]);
    }

  3. #3
    Senior Member fantasio's Avatar
    Join Date
    May 2000
    Location
    at the progress bar
    Posts
    409

    Cool Idea !

    thanks

  4. #4
    Junior Member
    Join Date
    Jan 2007
    Posts
    4
    A more direct answer that doesn't require you to reprogram your interval names was obtained from the blog below. I've included the relevant snippet here but there are some other useful tidbits at Ted on Flex.

    Code:
    Or if you simply want to clear out all the Intervals within the Flash Player: 
    
    i = setInterval(function(){},100) + 1 
    while(i--){ 
    clearInterval(i) 
    }

  5. #5
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    just push the timers into an array, then loop through the array to clear them all:
    Code:
    var timers:Array = new Array();
    
    var i:Number = setInterval(....);
    timers.push(i);
    
    function clearAllIntervals(a:Array):Void
    {
       for(var i:Number=0; i<a.length; i++)
       {
          clearInterval(a[i]);
       }
    }
    with that function, you can then just call, clearAllTimers(timers); and it will do the job.

  6. #6
    Junior Member
    Join Date
    Jan 2007
    Posts
    4
    The advantage to the code that I posted is that it doesn't require any changes to your current code. You can simply drop the function in and it will clear out all of the intervals. Of course, your way is probably cleaner, but sometimes nuking everything can be useful. :-)

    Also, how funny is it that this thing went dead for 5 years, then I replied and within 1 hour someone else replied? Crazy. Sorry to bring back an old thread, but it turned out to be applicable to my current problem (I stumbled across this forum through a Google search for the solution).
    Last edited by Phoenix00017; 08-07-2007 at 03:21 PM.

  7. #7
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    Oh, haha, I did not even look at the date!

    I guess the same principals still apply.

  8. #8
    Junior Member
    Join Date
    Jan 2011
    Posts
    2

    Thumbs up @ Phoenix00017

    Your "i = setInterval(function(){},100) + 1" code just saved me hours of headache.

    I've had a nested clip with a pausei function that wouldn't clear/null and was coming in conflict with "_root.gotoAndPlay("page"+_root.page);" code.

    I've spent almost two days on it... and nothing I found worked until I tried this.

    THANK YOU!!!!!!

  9. #9
    Junior Member
    Join Date
    Jan 2007
    Posts
    4
    Well, credit goes to the blog I quoted from, but awesome to hear it helped.

    Also, I find it again hilarious that this thread manages to rise from the dead to be helpful for a second time. Check out the years of the posts: 2002, then nothing until 2007, then nothing until 2011. Crazy!

  10. #10
    Junior Member
    Join Date
    Jan 2011
    Posts
    2

    Cool Coolness

    Yeah, I noticed that. Ten years almost.
    I need to convert all this code to AS3, eventually. Just barely got a handle on AS2 when everything switched to AS3... But just glad I could find the info still.

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