# Timer Component

**URL:** <https://forum.kirupa.com/t/timer-component/219618>\
**Category:** flash\
**Created:** [March 18, 2007, 7:03pm UTC](https://forum.kirupa.com/t/timer-component/219618 "2007-03-18T19:03:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xannax](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/xannax/32/3350_2.png) [@Xannax](https://forum.kirupa.com/u/Xannax)\
**Post date:** [March 18, 2007, 7:03pm UTC](https://forum.kirupa.com/t/timer-component/219618/1 "2007-03-18T19:03:11Z")

</div>

I’m trying to create a timer component, just to play a bit with components and understand how they work.  
Here’s my code:

```auto
var TimerClock:Number = new Number(0)
var CurrTime = CurrTime
var EndTime = EndTime
var DoLoop:Boolean = DoLoop
var Ended:Boolean = false

var PlayClock = function(){
    Ended=false
    TimerClock = setInterval(IncrementClock,100)
    }

function ResetClock(){
    Ended=false
    CurrTime=0
    }

function IncrementClock(){
    CurrTime++
    if(CurrTime>=EndTime){
        if(DoLoop==false){clearInterval(TimerClock)}
        CurrTime=0;
        TimeEnd();}
    }

function TimeEnd(){
    trace("EndTime!!")
    }

```

Everything works fine. There’s something I’m not getting though. I would like my component to have a listener. I would then, when using it, use TimerClock.OnEnd() = function{custom stuff}, instead of checking in a loop if the timer got to the end or not.  
Am I clear enough? Basically, I want to be able to drop the timer component on stage and then add this:

Timer.BeginTime=0  
Timer.EndTime=10  
Timer.Begin()  
Timer.OnEnd()=function{trace(“it ended”)}

Is it possible?
