# Stuck on this timer code! Please help!

**URL:** https://forum.kirupa.com/t/stuck-on-this-timer-code-please-help/186480
**Category:** flash
**Created:** [April 21, 2006, 3:44pm UTC](https://forum.kirupa.com/t/stuck-on-this-timer-code-please-help/186480 "2006-04-21T15:44:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![hftw](https://avatars.discourse-cdn.com/v4/letter/h/a698b9/32.png) [@hftw](https://forum.kirupa.com/u/hftw)
#### Post date: [April 21, 2006, 3:44pm UTC](https://forum.kirupa.com/t/stuck-on-this-timer-code-please-help/186480/1 "2006-04-21T15:44:55Z")

</div>

Hi all!

I’m using this timer code for my project but im having a little problem understanding several of the lines. This code was attached to a frame on the main timeline, and a movie clip called my\_mc placed on the stage. Can anyone explain in detail what is happening and why for each of the lines in red? Thanks for any help! Much appreciated.

[COLOR=red]t0 = getTimer();

this.onEnterFrame = function(){

var t1 = getTimer() - t0;  
var s1 = Math.round(t1 / 1000);[/COLOR]  
var t2 = 60 - s1;  
if (t2 \<= 0)

delete this.onEnterFrame;  
t2 = 0;

my\_mc.swapDepths(666);  
my\_mc.removeMovieClip();

trace(t2);  
};

---

<div class="post-metadata">

### Author: ![joran420](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joran420/32/2329_2.png) [@joran420](https://forum.kirupa.com/u/joran420)
#### Post date: [April 21, 2006, 4:26pm UTC](https://forum.kirupa.com/t/stuck-on-this-timer-code-please-help/186480/2 "2006-04-21T16:26:34Z")

</div>

> [@hftw](#):
>
> Hi all!
> 
> I’m using this timer code for my project but im having a little problem understanding several of the lines. This code was attached to a frame on the main timeline, and a movie clip called my\_mc placed on the stage. Can anyone explain in detail what is happening and why for each of the lines in red? Thanks for any help! Much appreciated.
> 
> [COLOR=red]t0 = getTimer();
> 
> this.onEnterFrame = function(){
> 
> var t1 = getTimer() - t0;  
> var s1 = Math.round(t1 / 1000);[/COLOR]  
> var t2 = 60 - s1;  
> if (t2 \<= 0)
> 
> delete this.onEnterFrame;  
> t2 = 0;
> 
> my\_mc.swapDepths(666);  
> my\_mc.removeMovieClip();
> 
> trace(t2);  
> };

getTimer() starts the timer in t0  
gettimer returns the time elapsed since creation of t0…but its in miliseconds  
so divide by 1000 = seconds

---

<div class="post-metadata">

### Author: ![mathew\_er](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mathew\_er](https://forum.kirupa.com/u/mathew_er)
#### Post date: [April 21, 2006, 4:27pm UTC](https://forum.kirupa.com/t/stuck-on-this-timer-code-please-help/186480/3 "2006-04-21T16:27:04Z")

</div>

> t0 = getTimer();

getTimer() function returns number of milliseconds till start of the flash movie

> this.onEnterFrame = function(){

assings to “this” an onEnterFrame… it is following code terminated with “};” on the last line. This function is called on every frame.

> var t1 = getTimer() - t0;

This assings to variable “t1” time since “t0” was declared… it gets higher every frame

> var s1 = Math.round(t1 / 1000);

This assings to “s1” converted value of “t1” from milliseconds to seconds as 1 second = 1000 milliseconds.

Do you need something more or is it clear enough?
