找到一种方法,不过有分钟显示,只好凑合用了
程序如下
-- Timer Behavio
-- copyright ZZP Online, 1998.
-- Free for use by readers of
-- The Multimedia Handyman
-- Visit
www.director-online.com/
property pstartMin
property pstartSec
property pCountUp
-- time up (1) or count down (0) (default is down)
property pMyField
-- the name of the field to which the
--behavior is applied
property pStopTime
-- a switch for the timer
property pSecNow
property pMinNow
-- this handler allows the user
-- to set the starting time
-- and choose between counting up or down
on getPropertyDescriptionList
set p_list = [#pCountUp: [ #comment: "Click for count UP:",#format: #boolean,#default: 0 ], #pStartMin: [ #comment: "Starting Minutes:",#format: #integer, #default: 0 ,#range: [min:0,max:59]], #pStartSec: [ #comment: "Starting Seconds:", #format: #integer, #default: 0,#range: [min:0,max:59]]]
return p_list
end
-- The beginSprite handler adds
-- the behavior object to
-- "the actorList" so that we can
-- use the stepFrame handler
-- to update the time display on every new frame.
on beginSprite me
set pStopTime = FALSE
add the actorList, me
set pMyField = the name of member(the member of sprite the spriteNum of me)
if NOT pCountUp then
set pStartMin = pStartMin - 1
set pStartSec = pStartSec + 60
end if
startTimer
end
-- The stepFrame handler checks
-- to see whether to count
-- up or down, then calls the
-- appropriate handler.
on stepFrame me
if pCountUp then
countUp me
else if NOT pStopTime then
countDown me
end if
end
-- The countUp handler divides the ticks
-- elapsed by 60 to yield
-- seconds elapsed, and by 3600 to yeild
-- minutes elapsed. By using
-- the mod function with 60 as the parameter,
-- the seconds will start
-- over at 60. For example, when we get to
-- 67 seconds, we only want
-- to see ":07" in the seconds column. If
-- we calculate 67 mod 60, the
-- result is 7.
on countUp me
set secondsElapsed = the timer/60
set pSecNow = secondsElapsed mod 60
set pMinNow = the timer/3600
displayTime me
end
-- The countDown handler does the same as
-- the countUp handler, except
-- that it subtracts our elapsed time from
-- the original start time. The
-- last part of the handler checks to see
-- if the timer is down to zero,
-- and if so, it sets our property "pStopTime"
-- to TRUE. When pStopTime
-- is TRUE, the stepFrame handler stops
-- calling this handler.
on countDown me
set secondsElapsed = the timer/60
set pSecNow = pStartSec - (secondsElapsed mod 60)
set pMinNow = pStartMin - (the timer/3600)
if pSecNow > 60 then
set pMinNow = pMinNow + 1
set pSecNow = pSecNow - 60
end if
displayTime me
if pMinNow = 0 and pSecNow = 0 then
set pStopTime = TRUE
end if
end
-- Finally, the displayTime handler plugs
-- the values for minutes and
-- seconds elapsed into a variable called
-- "showTime", then puts showTime
-- into the field for display.
on displayTime me
if pSecNow = 60 then
put pMinNow + 1 & ":00" into showTime
else if pSecNow < 10 then
put pMinNow & ":0" & pSecNow into showTime
else
put pMinNow & ":" & pSecNow into showTime
end if
put showTime into field "timer"