This is a basic countdown timer. You need to place one copy on a non field item as the master counter and then one on each field you want to use to display the results.
--Copyright 1999 Chuck Neal
--chuck@mediamacros.com
--If you find this code helpful, send me an e-mail and let me know. :-)
on getPropertyDescriptionList me
p_list = [:]
if [#field, #text].getOne(sprite(the currentSpriteNum).member.type) = 0 then
--not a text or field member, use as the counter "base"
p_list.addProp(#cYear, [#format : #integer, #comment : "Countdown year (in 4 digit format):", #default : 2000])
p_list.addProp(#cMonth, [#format : #symbol, #comment : "Countdown month:", #default : #January, #range : [#January, #February, #March, #April, #May, #June, #July, #August, #September, #October, #November, #December]])
p_list.addProp(#cDay, [#format : #integer, #comment : "Countdown Day:", #default : 1, #range : [#min : 1, #max : 31]])
p_list.addProp(#cHour, [#format : #integer, #comment : "Countdown Hour:", #default : 0, #range : [#min : 0, #max : 23]])
p_list.addProp(#cMin, [#format : #integer, #comment : "Countdown minute:", #default : 0, #range : [#min : 0, #max : 59]])
p_list.addProp(#cSec, [#format : #integer, #comment : "Countdown second:", #default : 0, #range : [#min : 0, #max : 59]])
p_list.addProp(#whatItem, [#format : #symbol, #comment : "What item is this?:", #default : #Master, #range : [#Master]])
else
--is a field, which one?
p_list.addProp(#whatItem, [#format : #symbol, #comment : "What item is this?:", #default : #Day, #range : [#Day, #Hour, #Min, #Second, #All, #UntilSince]])
end if
return p_list
end
on exitFrame me
if whatItem = #master then
--only run on the master control
theMonth = [#January, #February, #March, #April, #May, #June, #July, #August, #September, #October, #November, #December].getOne(cMonth)
theDays = date(cYear, theMonth, cDay) - the systemDate
theTime = getTime()
if theDays > 0 then
--before the day
beforeAfter = "before"
else if theDays < 0 then
--after the day
beforeAfter = "after"
else
--same day, dig deeper
if theTime[1] > cHour then
beforeAfter = "after"
else if theTime[1] < cHour then
beforeAfter = "before"
else
--same hour, dig deeper
if theTime[2] > cMin then
beforeAfter = "after"
else if theTime[2] < cMin then
beforeAfter = "before"
else
--same min, dig deeper
if theTime[3] > cSec then
beforeAfter = "after"
else
beforeAfter = "before"
end if
end if
end if
end if
timeList = getDate(me, theDays, theTime, beforeAfter)
sendAllSprites(#updateCount, timeList, beforeAfter)
end if
end
on updateCount me, timeList, beforeAfter
case whatItem of
#Day :
sprite(spriteNum).member.text = string(timeList[1])
#Hour :
sprite(spriteNum).member.text = string(timeList[2])
#Min :
sprite(spriteNum).member.text = string(timeList[3])
#Second :
sprite(spriteNum).member.text = string(timeList[4])
#All :
sprite(spriteNum).member.text = timeList[1] && "," && timeList[2] & ":" & timeList[3] & ":" & timeList[4]
#UntilSince :
if beforeAfter = "after" then
sprite(spriteNum).member.text = "Since"
else
sprite(spriteNum).member.text = "Until"
end if
end case
end
on getTime me
baseTime = the long time
the itemDelimiter = ":"
thisHour = integer(baseTime.item[1])
thisMin = integer(baseTime.item[2])
thisSec = integer(baseTime.item[3].char[1..2])
numChars = baseTime.char.count
amPm = baseTime.char[(numchars - 1)..numChars]
if amPm = "pm" then
if thisHour < 12 then
thisHour = thisHour + 12
end if
else
if thisHour = 12 then
thisHour = 0
end if
end if
return [thisHour, thisMin, thisSec]
end
on getDate me, theDays, theTime, beforeAfter
if beforeAfter = "before" then
theSec = cSec - theTime[3]
theMin = cMin - theTime[2]
theHour = cHour - theTime[1]
else
theSec =theTime[3] - cSec
theMin = theTime[2] - cMin
theHour = theTime[1] - cHour
end if
if theSec < 0 then
--wrap around and borrow from the minutes
theSec = theSec + 60
tOffset = 1
else
tOffset = 0
end if
theMin = theMin - tOffset
if theMin < 0 then
--wrap around and borrow from hours
theMin = theMin + 60
tOffset = 1
else
tOffset = 0
end if
theHour = theHour - tOffset
if theHour < 0 then
--wrap around and borrow from the days
thehour = 24 + theHour
tOffset = 1
else
tOffset = 0
end if
theDays = theDays - tOffset
return [theDays, theHour, theMin, theSec]
end
on getBehaviorDescription me
describe = "This is a basic countdown behavior. Drop it on a non text/field member to set up the master timer and then drop it on each field/text member you want to use to display."
describe = describe & return & "Once it passes the date it can turn a field from saying " & quote & "Until" & quote & " to one saying " & quote & "Since" & quote
return describe
end
Contact
MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA