Intoduction
I had this problem. I wanted to have a looping sound playing along with a movie and fade out as the movie reached its end.
Flash has a fade out effect in the Edit Envelope panel. There you can force a certain loop to fade out.
This didn't suit my case because I didn't know the exact loop to fade out since a movie, loaded with tweens and heavy graphics, doesn't last the same in every computer.
There's also the Stream option, but it usually turns the music to sound terrible.
Even worse, combined with ActionScript, can turn the movie into a disaster since it skips frames.
So I found a solution in creating a FadeOut movie clip that, attached to the movie, can fade any music out no matter the computer it is played in.
Step by Step
- Press Ctrl+R to import a sound file, open your library and right-click on it.
Select "Linkage...", "Export this symbol", enter "Loop" in the "Identifier" box and press OK. - Press Ctrl+F8 to make a new movie clip and name it fadeOutMC.
- Select the 100th frame of fadeOutMC and press F6 to create a keyframe.
Double-click on it and in the Actions panel enter stop (); - Return to the main timeline.
Double-click on frame 1 and enter the following :myMusic = new Sound(); myMusic.attachSound("Loop"); myMusic.start( 0, 1000 );Meaning : We create a new sound object (myMusic), attaching our "Loop" sound and make it play 1000 times. - Select frame 30 and press F6 to create a new keyframe.
Drag fadeOutMC from the library to the stage.
Then select frame 31 and press F6 again.
Double-click on it and in the Actions panel enter stop (); (to prevent the movie from looping in testing mode).
On the stage right-click on fadeOutMC (a small cross) and select "Actions".
Enter the following :onClipEvent(enterFrame) { volumeValue = 100 - _currentframe; _root.myMusic.setVolume(volumeValue); }What we do is :
On the 30th frame our fadeOutMC starts playing.
Since it's a movie clip it won't stop at the next frame, but it will play untill it reaches a stop() in its own timeline (the 100th frame).
Then we set a variable (volumeValue) and its value is 100 minus the frame fadeOutMC currently is.
This value decreases as fadeOutMC plays.
Then we set the volume to our sound object to the value of our volumeValue variable. - Test your movie.
After it gets to the 30th frame the music will fade out.
Possibly Asked Questions :
o What if I want a fade in?
Then in step 5 you enter volumeValue = _currentframe;
The value will increase as the movie plays, but you must note that all sounds start with the volume set to 100.
o What if I want to fade out a sound that is inside another movie clip?
Then you drag fadeOutMC in your movie clip at the frame you want your fade out to start,
but in step 5 you should enter the path to your movie clip.
_root.yourMovie.myMusic.setVolume(volumeValue);
o What if I want to fade the music out in less than 100 frames?
Then you make fadeOutMC to have as many frames as you want your fade out to last,
but in step 5 you must multiply _currentframe with a number, that when multiplied with fadeOutMC's last frame, gives 100.
That means that if you want your fade out to last 25 frames, you must enter : volumeValue = 100 - (_currentframe*4);
o I don't hear any music after the fade out but is it still playing?
Yes it is.
If you want it to stop then you should enter _root.myMusic.stop(); in fadeOutMC's last frame. (In step 3)
That's all. Enjoy
Agamemnon
| » Level Intermediate |
Added: : 2001-12-20 Rating: 8.76 Votes: 144 Hits: 5154 |
| » Author |
| Agamemnon lives in Greece. He is a professional musician (a Double Bass player) and a semiprofessional web author. He loves working with Flash while what hates the most is the incompatibility between browsers. |
| » Download |
| Download the files used in this tutorial. |
| Download (35 kb) |
discuss this topic to forum
