Flash5 timer script

  • DooMZ81
  • Newbie
  • Newbie
  • DooMZ81
  • Posts: 9
  • Loc: SIngapore

Post 3+ Months Ago

Need a simple flash 5 (not flashMX) timer script for my maze project.Reason is school is using flash5.Being searching the script but to no vain.

Thks
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

My apologies, I started this, but the file was MX.

I thought the code was MX compatible as well, until I realized that dynamic event handlers didn't exist in Flash 5.

The code I used was
Code: [ Select ]
timer = "Timer Not Started Yet";
function startTimer() {
    timerStartTime = getTimer();
    _root.onEnterFrame = function() {
        timer = Math.floor((getTimer()-timerStartTime)/1000);
        showTimer = timer+" second(s) passed";
    };
}
function stopTimer() {
    delete _root.onEnterFrame;
    showTimer = "Timer Stopped at "+timer+" seconds";
}
  1. timer = "Timer Not Started Yet";
  2. function startTimer() {
  3.     timerStartTime = getTimer();
  4.     _root.onEnterFrame = function() {
  5.         timer = Math.floor((getTimer()-timerStartTime)/1000);
  6.         showTimer = timer+" second(s) passed";
  7.     };
  8. }
  9. function stopTimer() {
  10.     delete _root.onEnterFrame;
  11.     showTimer = "Timer Stopped at "+timer+" seconds";
  12. }


Of course that is Flash MX. I will work out a Flash 5 solution as soon as I can, but if anyone else gets a chance sooner, go for it!
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

Ok, here's what I came up with.

Since Flash 5 doesn't support dynamic event handlers, or dynamic creation of clips, you will first need to create an empty movieclip symbol to house an onClipEvent(enterFrame).

Anywho, here's basic steps....

Code: [ Select ]
//timer not run yet notification (printed to textbox)
showTimer = "Timer Not Started Yet";
//have timer stopped from the beginning
_global.runTimer = false;
//function to start running the timer script
function startTimer() {
    _global.timerStartTime = getTimer();
    _global.runTimer = true;
}
//function to stop running the timer script
function stopTimer() {
    _global.runTimer = false;
}
  1. //timer not run yet notification (printed to textbox)
  2. showTimer = "Timer Not Started Yet";
  3. //have timer stopped from the beginning
  4. _global.runTimer = false;
  5. //function to start running the timer script
  6. function startTimer() {
  7.     _global.timerStartTime = getTimer();
  8.     _global.runTimer = true;
  9. }
  10. //function to stop running the timer script
  11. function stopTimer() {
  12.     _global.runTimer = false;
  13. }


Those actions will go in frame 1 of your movie.

Then, on an empty movieclip symbol on the stage you will apply these actions
Code: [ Select ]
onClipEvent (enterFrame) {
    //if the runTimer variable is true
    if (_global.runTimer) {
        //run the timer!
        timer = Math.floor((getTimer()-_global.timerStartTime)/1000);
        //print value to textbox
        _parent.showTimer = timer+" second(s) passed";
    }
}
  1. onClipEvent (enterFrame) {
  2.     //if the runTimer variable is true
  3.     if (_global.runTimer) {
  4.         //run the timer!
  5.         timer = Math.floor((getTimer()-_global.timerStartTime)/1000);
  6.         //print value to textbox
  7.         _parent.showTimer = timer+" second(s) passed";
  8.     }
  9. }


Now in my example there are 2 buttons. One of them contains this action
Code: [ Select ]
on (release) {
    startTimer();
}
  1. on (release) {
  2.     startTimer();
  3. }
and the other contains
Code: [ Select ]
on (release) {
    stopTimer();
}
  1. on (release) {
  2.     stopTimer();
  3. }



And last put not least, the last step in my example was to create a dynamic textbox on the stage that has the var name "showTimer".




Note: This is a Flash 5 recreation of the example I showed you in your other thread. It may not be exactly what you need, but the basic idea is still there, it sounds like all you will really need is to adjust when the startTimer() and stopTimer() functions are called (as well as not having it print to a textbox if you don't need that)

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 22 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.