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

Timer executing a function every X seconds?

Guest
Jul 30, 2009 Jul 30, 2009

Hello everyone,

I'm having no success getting a timer to work, let alone one that executes a function every X seconds (say every 10 seconds). This is my first attempt at using a timer and would appreciate any feedback.

package {
    import flash.display.*;
    import flash.events.*;
    import fl.transitions.*;
    import fl.transitions.easing*;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
   
    public class TimedColorTween extends MovieClip {
        private var colorTimer:Timer = new Timer(10000);
       
        public function TimedColorTween() {
            colorTimer.start();
           
            colorTimer.addEventListener(TimerEvent.TIMER, timerHandler);
        }
       
        public function timerHandler(e:TimerEvent):void {
            if (colorTimer %= 10) {
                trace ("10 seconds has passed")
                //insert function to execute color tween here later
            }
        }
    }
}

TOPICS
ActionScript
663
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
Enthusiast ,
Jul 30, 2009 Jul 30, 2009
LATEST

package {
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    import flash.display.Sprite;

    public class TimerExample extends Sprite {

        public function TimerExample() {
            var myTimer:Timer = new Timer(10000, 10);
            myTimer.addEventListener("timer", timerHandler);
            myTimer.start();
        }

        public function timerHandler(event:TimerEvent):void {
            trace(" 10 seconds passed");
        }
    }
}

This will work as calling the function timerHandler in evry 10 seconds for 10 times

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