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

Understanding a code-based timer

Community Beginner ,
May 01, 2013 May 01, 2013

The goal:

With the timeline stopped, a timer counts to a specified number of seconds, then performs an action (play, gotoAndPlay, etc).

Here's the code cobbled together from tutorials and forum generousity, but how do I set it to fire the action at 30 sec, or 60 sec?

stop();

var timer:Timer = new Timer(20, 100); // Sets delay to 100, repeatCount to 100

timer.addEventListener(TimerEvent.TIMER, stopper);

function stopper(event:TimerEvent):void {

    switch (timer.currentCount) {

        case timer.repeatCount:

                    timerText.text = "Done";

            timer.reset();

            break;

    }

}

function timerListener (e:TimerEvent):void {

           gotoAndPlay("2");

  // Code here will execute when triggered by a TimerEvent.TIMER event

}

timer.addEventListener(TimerEvent.TIMER, timerListener);

//fire the timer

timer.start();

//setup reset button

resetButton.addEventListener(MouseEvent.MOUSE_DOWN, resetBut);

//reset timer on call

function resetBut(event:MouseEvent):void {

timerText.text = "";

timer.reset();

timer.start();

}

I get that the answer's probably in the second line, but what do the 20, 100 correspond to? From my rough test the timer currently runs for about 3 seconds before triggering the event.

FLA posted here: https://my.syncplicity.com/share/kobzidmgnm/as3_timer-CT-simple

Thanks for any guidance...

TOPICS
ActionScript
746
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 , May 01, 2013 May 01, 2013

If you look up the Timer class in the Help documentation you will find the answers you seek.  If you are not familiar with how to do that, one simple way is to select the word "timer" in the Actions panel code and right click it and choose View Help at the bottom of the menu that appears.  The Timer class document should open.

In there you will find that the 20 and the 100 are the delay and repeatCount properties.

Translate
LEGEND ,
May 01, 2013 May 01, 2013

If you look up the Timer class in the Help documentation you will find the answers you seek.  If you are not familiar with how to do that, one simple way is to select the word "timer" in the Actions panel code and right click it and choose View Help at the bottom of the menu that appears.  The Timer class document should open.

In there you will find that the 20 and the 100 are the delay and repeatCount properties.

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
Community Beginner ,
May 01, 2013 May 01, 2013

I think I get it... Timer(20, 100) means a 20 millisecond delay is repeated 100 times = a 2 second interval. So if I want 30 seconds, I used Timer(10, 3000)

Thanks

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 ,
May 02, 2013 May 02, 2013
LATEST

If you want a 30 second timer and have no use for 10 msec intervals just specify a 30 second delay (30000 msecs).

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