Flash Education: Timer with a Reset Button

Home Food Mates • Members Tutorials Forum Buy Templates Contact Us 

 


Flash Tutorials

   

Flash Tutorial - Delays, Timers & Stop Watches

 

Free Flash Tutorial


Step 4    <<   Previous      Intro   1   2   3   4   5   6     Next   >>       >>   Webwasp Mates

 

A Timer with a Reset Button

Here we will look at creating a Timer with a Reset Button. This re-sets the Timer back to zero. There is another new feature in that the second label changes according to the elapsed time. So the Timer displays 1 second and then 2 seconds. Press the timers Reset Button and you will see:

Example D: Download the Flash file  Int 156d


Timer with reset button.

The label '' changes depending on the time:

  (not 1 seconds)

It is a small difference and most of you will have missed it, but of course you cannot have '1 seconds'. What is more interesting than being grammatically correct is how it is done.


Timer with Reset: The Stage

On stage the text box with the word 'seconds' has been removed and replaced with a blank Dynamic text box called: myLabel

Otherwise it is the same as the previous example - except for the Reset button which I will come back to.


Timer with Reset: The ActionScript

Place the following ActionScript in Frame 1:

myLabel = "seconds";
myTimer = setInterval(wait, 1000);
function wait() {
    mySeconds++;
    if (mySeconds == 1) {
        myLabel = "second";
    } else {
        myLabel = "seconds";
    }
}


Timer with Reset: ActionScript Line by Line

myLabel = "seconds";
Sets the Dynamic text box myLabel to display the word seconds at the start.

myTimer = setInterval(wait, 1000);
Calls the function every 1 second.

function wait() {
The start of the function

mySeconds++;
Adds 1 to the Dynamic text box mySeconds every time the function is called.

if (mySeconds == 1) {
If mySeconds equals 1 then...

myLabel = "second";
myLabel displays the word second

} else {
If mySeconds does not equal 1 then...

myLabel = "seconds";
myLabel displays the word seconds


Timer with Reset: The Reset Button

The Reset Button ActionScript is very simple:

on (release) {
    _root.mySeconds = 0;
}

         

Step 4    <<   Previous      Intro   1   2   3   4   5   6     Next   >>       >>   Webwasp Mates


Webwasp Community: Webwasp Mates & Dates

Why not try out webwasp's new community. Meet new people, find friends in your area: Webwasp Mates & Dates

34122 visitors to this page since April 06

 Top of Page Home Food Mates Members Tutorials Forum Buy Templates Contact Us 
 All material on this site is protected under international copyright © law. DO NOT reproduce any material from this site without written permission. Please ask as permission is often granted.