First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: Kenny Bellew

How to Synchronize Animation to a Specific Time within a Sound Object

This tutorial has already shown how to set a variable to equal a specific time within a sound object using the mySoundObject.position method. The following is a simple trick for capturing the exact positions you need.

In the Flash example Fig. 15 below, press the green "Example Sound" button. Then, as the sound plays, press the blue buttons to capture the sound object's position in seconds. This data can be used to start an animation at that exact time position for the sound object. The counting-numbers animation in the Flash example below (Fig. 15) is completely driven by sound position. Each animated number is displayed when with the position in the sound object for that number becomes true.

Fig. 15: Example of synchronizing animation to a time position of a sound object
  1. Define the sound object and create play, pause and stop buttons as described earlier.
  2. Create several dynamic text boxes, giving each a unique variable name. In the example below, the variable name is "position01".
    Fig. 16: Example of properties box and location of box to insert variable name.

  3. Place a button below each dynamic text box.
  4. On the first button, add the following:
    on(press) {
    And on the next button (and so on):
    on(press) {
  5. This will allow you to play your sound, and every time the sound comes to a point where you want the animation to change, press one of the buttons. The time position will be displayed in the text box. Make note of the time. For this example, let's assume the noted time is "15.5".
  6. The resulting code to start the animation would then be as follows:

    this.onEnterFrame = function () {
    if (mySound.position >= 15.5) {

    Notice, in the above example, ">=" was used instead of "==". The reason for this is related to frame rate. If the movie is moving along at 12-frames per second, and the sound position is only being checked twelve times per second. If your sound position happens to occur outside of one of these twelve times, the condition will not be true. Using the greater-than or equal-to symbol allows the condition to be deemed true as soon as it is able to sense that it is true.

For the Flash example Fig. 15 above, to display the "7" animation, the following code was used:

if (playing==true && mySound.position/1000 >= 8.5 && mySound.position/1000 <= 9.5) {

In the above example, when the sound object "mySound" reached 8.5 seconds, the contents of a dynamic text box with the variable name of "numbersText" was changed to "7".

» Level Intermediate

Added: 2002-08-13
Rating: 8.98 Votes: 664
(10 being the highest)
» Author
Kenny Bellew is a technical writer in Minneapolis, MN. He's currently interested in becoming involved in other writing-related Flash projects.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!


  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.