Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

setInterval timer not consistent?

Guest
Mar 03, 2013 Mar 03, 2013

I am working on an interactive flash program for a gallery installation that will be running for two weeks. This interactive flash program has buttons that users that take users to various "pages," like a website. However, as this is a gallery installation, I want the program to reset to the Splash page after a certain amount of time has passed. I have had limited success with setInterval(). It works great the first time, and the delay is what I set it as (I set it as 10 seconds for this test). However on subsequent tries (ie, after it has reset to the Splash page, and I start the process again), the delay is only about 1 or 2 seconds. What is going on here? Why is the delay not consitent?

Here is my simple code:

function FlashReset1():void

{

    gotoAndStop("SPLASH");

}

setInterval(FlashReset1,10000);

TOPICS
ActionScript
492
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 03, 2013 Mar 03, 2013

You are probably creating multiple instances of it and they end up all working and firing at different times.  You need to clear the Interval using clearInterval each time. 

You are probably better off using the Timer class, or you might even consider using the setTimeout function which doesn not repeat and does not need anything to clear it after it fires.

Translate
LEGEND ,
Mar 03, 2013 Mar 03, 2013

Looks like you never clear interval. Because it runs indefinitely next time you hit the code you shown - it may be any number because you most probably hit it in between.

Also, I suggest you use Timer instead of setInterval - it is cleaner and more manageable.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 03, 2013 Mar 03, 2013
LATEST

You are probably creating multiple instances of it and they end up all working and firing at different times.  You need to clear the Interval using clearInterval each time. 

You are probably better off using the Timer class, or you might even consider using the setTimeout function which doesn not repeat and does not need anything to clear it after it fires.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines