---------------------------------
property pStartTime
property pTime
property pPause
on beginSprite me
--creates the timeOut object and give it a countdown of 20 seconds(1 sec = 1000 ticks).
timeout("timer").new(pStartTime * 1000, #timeUp, sprite(me.spriteNum))
pPause = 0
end
on exitframe me
--converting the time into strings for display if timer isn't paused
if pPause = false then
pTime = ((timeOut("timer").time) - (the milliseconds))
mySeconds = pTime/1000
m = string(pTime/10).char.count
myMillis = string(pTime/10).char[m-1..m]
--faking the 0 in front if the seconds is less than 10
if mySeconds > 9 then
myTime = string(mySeconds & ":" & myMillis)
sprite(me.spriteNum).member.text = myTime
else
myTime = string("0" & mySeconds & ":" & myMillis)
sprite(me.spriteNum).member.text = myTime
end if
end if
end
on mouseUp me
--maybe will enhance accuracy of timer
the timeOutLapsed = 0
--record the time where it stops and delete the timeOut object.
--if play resumes, creates a new timeOut object --with the recorded time as its period.
if pPause = false then
timeOut("timer").forget()
pPause = true
else
timeOut("timer").new(pTime, #timeUp, sprite(me.spriteNum))
pPause = false
end if
end
end
on timeUp me
--remove the time object and stops the time.
pPause = true
sprite(me.spriteNum).member.text = string("00:00")
timeOut("timer").forget()
-- Do something here.
end
on getPropertyDescriptionList
list = [:]
addProp list, #pStartTime, [#Comment: "Start Time(in seconds)", #format: #integer, #default: 20]
return list
end
---------------------------------