|
|
|
Pauseable Timer with Progress Bar
Added on 3/11/2003
|
|
Compatibilities:
|
This item has not yet been rated
|
This behavior initialises a timer, and uses a sprite on stage to show the progress. The timer can be paused and restarted.
The orientation of the progress bar may be horizontal or vertical, and may increase or decrease. Optional display fields can show the progress in time (minutes and seconds) or percentage.
A demonstration of the script can be seen at http://users.pandora.be/somnirealm/Mediamacros/PTimer.htm
--This is a set of behaviors. There is one timerscript, which should be placed on top of a sprite that will act as a progress bar, and 5 additional behaviors from which you can choose to interact with the bar. You don't need them all ; just pick the ones you need...
---The following is the main Timer-script :
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
-- Pauseable Timer with progress bar 1.1
-- copyright (c) 2003, Dimitri Leveugle
-- To use this behavior, drag it to the sprite you want to use as a progress bar, set
the required parameters, and run this baby !
-- New in version 1.1
----> a bug involving the time-display of decreasing large time units has been fixed.
----> new controls to interact with the timer.
-------------------------------------------------------------------------------
-- BE SURE TO READ THE FOLLOWING CAREFULLY, OR YOUR SCRIPT MIGHT NOT WORK ! ---
-------------------------------------------------------------------------------
-- If there are NO FIELDS in your movie, and you don't wish to use the display
options of the script, type in "nihil". If you don't do this the behavior
WILL NOT WORK !!
--If there ARE FIELDS in your movie, but you don't want to use the display options of
the script, just create a dummy field in your cast, and point all properties to that
member.
--If you want to use ONLY ONE display option, create one field to fit your needs,
and point the display option you won't use to a dummy field.
---Note that you can scale the progress bar to the left, right or center depending on
the registration point of the castmember.
---You can incorporate several progressbars in 1 movie, each using different
timer-settings. However they CAN'T APPEAR AT THE SAME TIME in 1 frame. If you do
this, you'll get some freaky results...
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
property pSpWidth --- the width of the progress bar
property pSpRight --- right most point of the progressbar sprite (not the castmember)
property pSpLeft --- left most point of the progressbar sprite (not the castmember)
property pSpTop --- the top most point of the progressbar sprite (not the castmember)
property pSpBottom --- the bottom most point of the progressbar sprite (not the castmember)
property pSpHeight --- the height of the progress bar
property pSpOrientation -- shows orientation : horizontal or vertical
property pPastSeconds ---shows how many seconds the scrollbar has been running
property pPastMinutes ---shows how many minutes the scrollbar has been running
property pTimerStart ---this variable contains the value of the ticks when first started
this value is set in the start-button
property pTimerStop ---shows how many ticks the bar must run to finish
property pStartTicks ---shows the initial value of the timer
this value is set in the start-button
property pFinish ---shows whether the progress bar has reached its end
property pIsWorking ---shows whether the timer is working
property pTicksPast ---shows how many ticks the timer has been actively running, not
counting the pauses
property pCounter -- a variable for timedisplay purposes only
property pSecs ---shows how many seconds the progress bar must run to reach its end
this value is set by the user
property ptimer -- this property contains the name of the filed that is to be used to
show the past time in minutes and seconds.
property pPercent --show how many percent of the scrollbar has passed or must pass
property pdirection --shows if the progress bar must increase or decrease in size
the display fields reflect this setting.
on getBehaviorDescription me
return
"TIMER WITH PROGRESS BAR" & RETURN & RETURN &
"This behavior initialises a timer, and uses a sprite on stage
to show the progress. The timer can be paused and restarted.
The orientation of the progress bar may be horizontal or vertical,
and may be set to increase or decrease. Optional display fields
can show the progress in time (minutes and seconds) or percentage." & RETURN & RETURN &
"IMPORTANT : Read the notes in the script to set up the display fields." & RETURN & RETURN &
"Use this script in conjunction with the accompanying steering scripts."
end getBehaviorDescription
on getBehaviorTooltip me
return
"Place this script on a sprite that will function as progress bar." & RETURN & RETURN &
"Use the accompanying scripts to interact with the timer." & RETURN & RETURN &
"Read the notes in the script to set up the display fields."
end getBehaviorTooltip
on getPropertyDescriptionList me
set pdlist to [:]
addprop pdlist, #pSecs, [#comment:"How many seconds?", #format:#integer, #default:30]
addprop pdlist, #pTimer, [#comment:"Select the field to display the time:", #format: #field, #default:""]
addprop pdlist, #pPercent, [#comment: "Select the field to display the percentage:", #format: #field, #default:""]
addprop pdlist, #pDirection, [#comment: "Count which way?", #format:#symbol, #default:#increase, #range:[#increase, #decrease]]
return pdlist
end getPropertyDescriptionList
on beginsprite
---reset variables
pCounter=0
pTicksPast = 0
pFinish = 0
pIsworking=0
pPastSeconds=0
---if there is a field defined for pTimer, reset the timer
if pTimer <> "nihil" then
put "--" into field pTimer
else
nothing
end if
---if there is a field defined for ppercent, reset the timer
if pPercent <> "nihil" then
put "--" into field pPercent
else
nothing
end if
---calculate how many ticks the timer should run
pTimerStop = pSecs * 60
--calculate the width of the sprite on stage that serves as a progress bar
pSpRight = the Right of sprite(the currentspritenum)
pSpLeft = the left of sprite(the currentspritenum)
pSpWidth = pSpRight - pSpLeft
--calculate the height of the sprite on stage that serves as a progress bar
pSpBottom = the bottom of sprite(the currentspritenum)
pSpTop = the Top of sprite(the currentspritenum)
pSpHeight = pSpBottom - pSpTop
--calculate orientation
if pSpHeight > pSpwidth then
pSpOrientation = #vertical
else
pSpOrientation = #horizontal
end if
--calculate display of progress bar at initialisation
if pSpOrientation = #horizontal then
if pDirection = #decrease then
sprite(the currentspritenum).width = pSpwidth
else
sprite (the currentspritenum).width = 0
end if
else
if pDirection = #decrease then
sprite(the currentspritenum).height = pSpHeight
else
sprite (the currentspritenum).height = 0
end if
end if
end
on enterframe
if pIsWorking = 1 then
scroller
else
nothing
end if
end
on activate
---activate progress bar---
if pIsWorking=0 then
starter
else
---stop progress bar---
stopper
end if
end
on starter
if pIsworking=0 then
starttimer
pIsWorking=1
pTimerStart = the ticks
pStartTicks = the timer
else
nothing
end if
end
on stopper
if pIsWorking=1 then
pIsWorking=0
pTimerTickStop = pTimerStart + pTimerStop
pTimerTicksLeft = pTimerTickStop - the ticks
pTickspast = pTicksPast + (pTimerStop - pTimerTicksLeft)
else
nothing
end if
end
on restarter
---reset variables
pCounter=0
pTicksPast = 0
pFinish = 0
pPastSeconds=0
pPastMinutes=0
starttimer
pIsWorking=1
pTimerStart = the ticks
pStartTicks = the timer
end
on resetter
---reset variables
pCounter=0
pTicksPast = 0
pFinish = 0
pPastSeconds=0
pPastMinutes=0
starttimer
pIsWorking=0
pTimerStart = the ticks
pStartTicks = the timer
--reset the display fields
if pTimer <> "nihil" then
put "--" into field pTimer
else
nothing
end if
if pPercent <> "nihil" then
put "--" into field pPercent
else
nothing
end if
---reset the progress bar
if pSpOrientation = #horizontal then
if pDirection = #decrease then
sprite(the currentspritenum).width = pSpwidth
else
sprite (the currentspritenum).width = 0
end if
else
if pDirection = #decrease then
sprite(the currentspritenum).height = pSpHeight
else
sprite (the currentspritenum).height = 0
end if
end if
end
on scroller me
------------------------------------------------------------
--recalculate the value of seconds in minutes and seconds---
------------------------------------------------------------
if pDirection = #increase then
if pPastSeconds < #pSecs then
pPastSeconds = (the ticks - value(pTimerstart - pTicksPast)) / 60
pPastMinutes = pPastSeconds/60
if pPastSeconds > 59 then
pPastSeconds = pPastSeconds - (pPastMinutes*60)
end if
end if
else
pPastMinutes = (pSecs/60).integer-pCounter
pPastSeconds = pSecs - (pPastMinutes*60)-((the ticks - value(pTimerStart - pTicksPast))/60)
if pPastseconds = -1 then
pCounter = pCounter + 1
end if
end if
-----------------------------------
---controls progressbar movement---
-----------------------------------
---when the timer reaches its end
if the timer > pStartTicks + pTimerStop - pTicksPast then
if pFinish=0 then
pFinish=1
if pTimer <> "nihil" then
put pPastMinutes && "min" && pPastSeconds && "sec" into field pTimer
else
nothing
end if
workhandler
else
nothing
end if
else
----------------------------------------------
---calculate the progress bar while running---
----------------------------------------------
-----HORIZONTAL BAR-------
--------------------------
if pSpOrientation = #horizontal then
timeelapsed = the timer + pTickspast
percenttime = (timeelapsed * 1.000/pTimerStop)
---if decreasing ---
if pdirection = #decrease then
percentage = 100 - (percenttime * 100).integer
if pPercent <> "nihil" then
put percentage && "%" into field pPercent
else
nothing
end if
sprite(the currentspritenum).width = pSpWidth - (percenttime * pSpWidth)
if pTimer <> "nihil" then
put pPastMinutes && "min" && pPastSeconds && "sec" into field pTimer
else
nothing
end if
else
---if increasing---
percentage = (percenttime * 100).integer
if pPercent <> "nihil" then
put percentage && "%" into field pPercent
else
nothing
end if
sprite(the currentspritenum).width = percenttime * pSpWidth
if pTimer <> "nihil" then
put pPastMinutes && "min" && pPastSeconds && "sec" into field pTimer
else
nothing
end if
end if
else
--------------------
---VERTICAL BAR-----
--------------------
timeelapsed = the timer + pTickspast
percenttime = (timeelapsed * 1.000/pTimerStop)
---if decreasing ---
if pDirection = #decrease then
percentage = 100 - (percenttime * 100).integer
if pPercent <> "nihil" then
put percentage && "%" into field pPercent
else
nothing
end if
sprite(the currentspritenum).height = pSpHeight - (percenttime * pSpHeight)
if pTimer <> "nihil" then
put pPastMinutes && "min" && pPastSeconds && "sec" into field pTimer
else
nothing
end if
else
---if increasing---
percentage = (percenttime * 100).integer
if pPercent <> "nihil" then
put percentage && "%" into field pPercent
else
nothing
end if
sprite(the currentspritenum).height = percenttime * pSpHeight
if pTimer <> "nihil" then
put pPastMinutes && "min" && pPastSeconds && "sec" into field pTimer
else
nothing
end if
end if
end if
end if
end
on workhandler
---------------------------------------------
--do whatever you want when all is finished---
---------------------------------------------
beep
end
--The following script lets you pause and start the timer.
property pSpriteBar
on getPropertyDescriptionList me
set pdlist to [:]
addprop pdlist, #pSpriteBar, [#comment:"Select which sprite to control", #format:#integer, #default:0]
return pdlist
end getPropertyDescriptionList
on getBehaviorTooltip me
return
"This script will pause the progress bar.
Clicking again will continue the progress bar."
end getBehaviorTooltip
on mousedown
sendSprite (pSpriteBar, #activate)
end
--The following script restarts the timer.
property pSpriteBar
on getPropertyDescriptionList me
set pdlist to [:]
addprop pdlist, #pSpriteBar, [#comment:"Select which sprite to control", #format:#integer, #default:0]
return pdlist
end getPropertyDescriptionList
on getBehaviorTooltip me
return
"This script will restart the progress bar.
The bar will start running automatically."
end getBehaviorTooltip
on mousedown
sendSprite (pSpriteBar, #restarter)
end
--The following resets the timer. Contrary to the 'restart'-behavior, the timer will not start running automatically.
property pSpriteBar
on getPropertyDescriptionList me
set pdlist to [:]
addprop pdlist, #pSpriteBar, [#comment:"Select which sprite to control", #format:#integer, #default:0]
return pdlist
end getPropertyDescriptionList
on getBehaviorTooltip me
return
"This script will reset the progress bar to its initial values.
The bar will not start running automatically."
end getBehaviorTooltip
on mousedown
sendSprite (pSpritebar, #resetter)
end
--The following starts the timer. When the timer is already running, this will have no effect.
property pSpriteBar
on getPropertyDescriptionList me
set pdlist to [:]
addprop pdlist, #pSpriteBar, [#comment:"Select which sprite to control", #format:#integer, #default:0]
return pdlist
end getPropertyDescriptionList
on getBehaviorTooltip me
return
"This script will start the progress bar."
end getBehaviorTooltip
on mousedown
sendSprite (pSpritebar, #starter)
end
--And finally, the following will stop the timer. When the timer isn't working, this will have no effect.
property pSpriteBar
on getPropertyDescriptionList me
set pdlist to [:]
addprop pdlist, #pSpriteBar, [#comment:"Select which sprite to control", #format:#integer, #default:0]
return pdlist
end getPropertyDescriptionList
on getBehaviorTooltip me
return
"This script will stop the progress bar."
end getBehaviorTooltip
on mousedown
sendSprite (pSpritebar, #stopper)
end
|
|