• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 7. Scripted Animation Basics > Calling Code at Specific Intervals

Calling Code at Specific Intervals

Now that you have a subtle animated background, it's time to add text to the SWF file. You should already have an embedded font in your Library from a previous exercise in this chapter. This example shows you how to create text fields on the fly, trigger scripts at timed intervals, and use a new method in the Tween class: continueTo(), which allows you to continue animating an object. By using the setInterval() function, you can make Flash suspend code execution until an internal timer reaches a certain number of milliseconds (thousandths of a second).

If you set an interval of 2000 milliseconds, Flash calls a specific function after roughly two seconds. It bears mentioning that it won't call the function at exactly 2000 milliseconds, but usually it calls it within a range of 2050–2100 milliseconds—so close enough to 2000 milliseconds that it usually can't be noticed. If you want to see how accurate the setInterval() function calls your function, you can try the following code snippet in a new Flash document:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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