First time here? First time here? Newsletter Signup Newsletter
651326 Members and growing! | Flash Jobs
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) {
    position01=mySound.position/1000
    }
    And on the next button (and so on):
    on(press) {
    position02=mySound.position/1000
    }
  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) {
    _root.gotoAndPlay(26)
    }
    }

    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) {
_root.numbers.numbersText="7"
}

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!

Comments

  • 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: doc_chin7
» Description:

The flash's horizontal road drive was done in CS4 and was upgraded to CS6. The car responds to right/ left key and flash will auto-generate the movement of roads from left-right or right-left based on random number. Have fun driving in this virtual environment and avoid other cars... :) If you are creative, a road driving game can be created from it.

Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
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: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.