<A HREF="/Tech" TARGET="_self"><IMG SRC="FT-Logo.gif" WIDTH=137 HEIGHT=70 BORDER=0></A>
Plug & Play - Time Delay Functions

We have two Plug & Play time delay functions. One that counts up and one that counts down. They are both included in the Time Delay MC (instance name Count). The time will run slightly over the time delay you have set because we are looping between Flash frames and can not constantly check the time. The time inaccuracy is usually less than one tenth of a second and averages about + 0.05 seconds.

How to create a delay.
If you have installed the Plug and Play Libraries FLA in your Libraries folder use step 1B instead of 1A

1A) Open the Time Delay Plug and Play movie and copy the movie clip or the frame it is in from the Time Delay MC layer of the Plug and Play FLA to your movie. Usually you will put it in its own layer in your movie so it will always be available.

1B) Use this step if you have installed the Plug and Play Libraries FLA.
Select Libraries > _Plug_Play.
Drag Count - Time Delay from the libray menu just opened to its new layer.
Add the Instance name Count to the Movie Clip.

2) Put a Stop action in the main timeline where your movie will pause.

3) In the pause frame (or a button available there) place a Call action (as below) to the time delay routine. Preceed it with a delay setting if you do not want the time delay to be the default 5 seconds. The delay time is set in seconds with the variable Delay on the main timeline.

      Set Variable: "Delay" = nextdelay
                   or
      Set Variable: "/:Delay" = 3            
4) When the delay has finished your movie will start playing from the next frame on the main timeline.

To have a 10 second time delay that counts up:

      Set Variable: "Delay" = 10
      Call ("/Count:Up")
To call a 5 second time delay (default), that counts down:
      Call ("/Count:Down")
How to display the countdown.
To display the countdown (or count up) time place a text field on the main timeline and set its variable as Elapsed. If you are not displaying the countdown, then it makes no difference which of the two functions you use.

<A HREF="/Tech" TARGET="_self"><IMG SRC="FT-Logo.gif" WIDTH=137 HEIGHT=70 BORDER=0></A>
Download FLA in Zip format
How does the delay function work.
In each of our Call functions we have 3 frames starting with the label we use in the Call (Up or Down). In the first frame of each of our functions we get the current time (which is in milliseconds from the time the movie started) and set it to the variable Start. We also set the delay time to 5 second if it has not already been set.
      If (/:Delay="")
            Set Variable: "/:Delay" = 5
      End If
      Set Variable: "Start" = GetTimer
The second frame of the function has no actions.
In the third frame we calculate the elapsed time by subtracting the Start time from the current time. We then convert it to seconds (by dividing it by a thousand) and set it the the variable Elapsed.
Set Variable: "/:Elapsed" = (GetTimer - Start)/1000
Then we compare it to the delay time and if it is less than Delay then we loop back to second frame which brings us back to the third frame and another check. This loop continues until the elaped time is equal to or greater than our desired delay when we issue a play action on the main timeline.
If (/:Elapsed < /:Delay)
      Go to and Play ("BeginUp")
Else
      Begin Tell Target ("/")
            Play
      End Tell Target
      Go to and Stop (1)
End If
Why not use Loop While?
Using Loop While you can make a very accurate timer, but because Flash has a limit of 200,000 player actions the maximum Loop While loop in Flash that can be made is just a little over 2 1/2 seconds. In addition, other actions in the loop or anywhere in the same Flash frame will add to the total player actions and will reduce the maximum delay time that can be achieved with a Loop While loop. If player actions exceed 200,000, then Flash will stop executing the current action and an errror message will be displayed.
      Set Variable: "Start" = GetTimer
      Loop While (x < Delay)
            Set Variable: "x" = (GetTimer - Start)
      End Loop
Because of the ease of use, good accuracy and unlimited time delays available most of your time delay needs can utilize our Plug and Play routine, but if you need a more accurate time delay for short periods of time you may be able to use Loop While.