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.
|
- Define the sound object and create play, pause and stop buttons as
described earlier.
- 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.
- Place a button below each dynamic text box.
- On the first button, add the following:
on(press) {And on the next button (and so on):
position01=mySound.position/1000
}on(press) {
position02=mySound.position/1000
} - 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".
- 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 |
| » 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. |
| Download (6170 kb) |
| » Forums |
| More help? Search our boards for quick answers! |
-
You must have javascript enabled in order to post comments.


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