I’m trying to create a timer component, just to play a bit with components and understand how they work.
Here’s my code:
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?