Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

timer question 1

Status
Not open for further replies.

anyideas

Programmer
May 2, 2002
127
GB
Hi,

I'm trying to create a countdown timer that last 60 seconds and depending on the time left of the timer updates a text field showing this.

However, I need to get this to work as the movie is playing and not just static on one frame.

I'm using director 8.5 to create in.

If anyone can held I'd really appriciate it.

Cheers

Mark
 
Hi,
Here's a timer I did some time ago, hope this helps.
Just copy the whole thing onto a text field and
span the sprite across your movie. Its actually a
behaviour. FYI, there's also a timer in the library.
Also, this timer is pausable.

Code:
---------------------------------
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
---------------------------------
 
hi qazs

Thats nearly exactly what I'm looking for :) cheers

The only thing is.. its counting upwards in this format:
0-80476.01
0-80476.02

I just want it to count from 0 to 5 minutes.. is that possible.

Also have an if condition..

if timer > 1 minute then
do condition
end if

.. where do I put this into the code?

Cheers again

Mark
 
The following behaviour will display the time elapsed in "x min y sec" format and also trigger an event when the timer reaches 1 minute mark.

Make a text member and place it on the Stage, extend the sprite as long as this time counting needs to be present in the Score. Then attach the following behaviour to it:
Code:
--
property eventFlag

on beginSprite me
  eventFlag = 0
  startTimer
end beginSprite

on enterFrame me
  if eventFlag < 1 then
    if the timer > 60*60 then
      eventFlag = 1
      alert(&quot;1 minute elapsed!&quot;)
      -- or put something useful here
    end if
  end if
  secElapsed = (the timer)/60
  secElapsed = secElapsed - (secElapsed mod 1)
  secToDisplay = secElapsed mod 60
  minToDisplay = (secElapsed - secToDisplay)/60
  sprite(me.spriteNum).member.text = &quot;&quot;
  if minToDisplay > 0 then
    sprite(me.spriteNum).member.text = minToDisplay && &quot;min&quot;
  end if
  sprite(me.spriteNum).member.text = sprite(me.spriteNum).member.text && secToDisplay && &quot;sec&quot;
end enterFrame
--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top