• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Workshop Chapter 10. Creating Timers

Using Flash’s getTimer() function the way we did in Workshop Chapter 9, “Creating a ToolTip Component,” is quite common. We saved the current getTimer() in a variable, and then kept checking to see whether “enough” time elapsed by rechecking getTimer() and comparing that to the variable we saved at the start. In this workshop chapter, we’ll make several timers that the user can start, stop, and pause. To give the timers their functionality, we’ll save the current getTimer() when the user starts the timer. Then, in every enterFrame event, we’ll see how many milliseconds have elapsed since the start. We can then easily convert this value into hours, minutes, seconds, and even fractions of seconds.

This workshop chapter should teach two concepts in particular: how to translate numbers between different formats (milliseconds into hours, for example) and how to use getTimer() in conjunction with the enterFrame event. In the end, of course, we’ll have a digital timer (see Figure W10.1). You’ll also see how easy it is to convert the timer to an analog timer. Finally, in the third section of this workshop chapter, we’ll build a timer that counts down.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint