View Full Version : fading sound both in and out
Julia
04-17-2003, 09:48 AM
Using the excellent tutorial at www.kennybellew.com recommended by one of you out there to learn to manipulate sound objects. I want to be able to fade a sound in and then fade it out five seconds before the end.
I have been successful with the fade in using:
beat = new Sound(this);
beat.attachSound("revival_b");
fadeIn01=1
beat.start(0, 2);
beatVolume = 0;
beat.setVolume(beatVolume);
this.onEnterFrame = function() {
if (fadeIn01 == 1) {
_root.beat.setVolume(beatVolume);
beatVolume = beatVolume+5;
if (beatVolume>50) {
fadeIn01 = 0;
}
}
}
Works a treat!
However, he suggests using this in the first frame for the fade out five seconds from the end:
this.onEnterFrame = function () {
myMusicDuration = _root.myMusic.duration / 1000; myMusicPosition = _root.myMusic.position / 1000;
fadeEnd = (myMusicDuration - 5);
if (fadeEnd <= songPosition && myMusicVolume>0 && playing==true) {
if (myMusicVolume<=1) {myMusicVolume=0} _root.myMusic.setVolume(myMusicVolume); myMusicVolume=myMusicVolume-1;
}
}
He does say however, that if the initial setVolume is set at 0 this will not work. Obviously, my inital volume is 0 and when I try putting this into my script, even setting the initial volume at say 1, all of the sound disappears!
Any help please as to how I can get both to work as I really need both fade in and out - I am new at this game and need it simple!!!
Julia
04-19-2003, 01:39 PM
Lots of hits but no replies!
It would even if you can see that I am attempting the impossible or making such a goof that it seems obvious to everyone else! Please tell me because its not at all obvious to me and believe me I have tried searching various forums etc.
Perhaps I am not very clear in what I am attempting!
I can find lots of tutorials where sound is faded in and then faded out on some action, but here I am trying to build in a fade at the end without any actions taking place - similar to simply editing the sound instance when loading directly to a timeline. However, I need to have it loading as a sound object and I need it to fade in when it does so. It will then play in the background whilst the user views various screens - and then should fade out gradually at the end of the last loop.
The tutorial I was using seemed just right as it sets the loop to fade dependent on reaching a point in duration. However, it doesnt seem to work loading this on the first frame as obviously my initial volume is 0.
Please take pity on a poor designer trying hard to learn actionscripting!! ;)
bluegel
04-22-2003, 09:17 AM
not sure what is wrong with it.
can you upload a sample file of what you have done?
Julia
04-22-2003, 08:41 PM
Thanks for your reply.
heres a very cutdown version of the animation - the backgrounds are all large files so I have cut them out - hence the completely white start so bear with it!
The sounds fades in beautifully with the script down to the comment //Closes function. But when I add in the last bit to make the sound fade out automatically, all of the sound disappears!
I realise that this needs the volume to be greater than 0 at the start, but even setting the initial volume to 1 doesnt seem to work.
I am new at this so my gaff is probably blindingly obvious to everyone bar me!
Any help would be really appreciated.
Julia
04-22-2003, 09:47 PM
Apologies - I just cant get this file below the max file size, even tho I only have a couple of sample buttons and a much compressed music clip, (which even originally was only 169kb) on the test version, its still over 1.5mb.
If anyone is still interested, I have the music instance revival_b in a movie clip called beat and with this action calling into play
beat = new Sound(this);
beat.attachSound("revival_b");
fadeIn01 = 1;
beat.start(0, 1);
beatVolume = 0;
beat.setVolume(beatVolume);
this.onEnterFrame = function() {
//
//Fade In
//
if (fadeIn01 == 1) {
// fadeIn01 can be set to 1 when a button is
// pressed, when a frame is reached or many other ways.
_root.beat.setVolume(beatVolume);
// Sets the volume for the sound object "beat"
// to the variable "beatVolume" every time the
// frame is entered during the movie clip loop.
beatVolume = beatVolume+5;
// Increments the variable "beatVolume" by 5.
// Increase or decrease this to change the speed of
// the fade from 0 to 100.
if (beatVolume>30) {
fadeIn01 = 0;
// This stops the "beatVolume" from incrementing
// by making the if-statement false once the volume
// reaches 30%.
}
//Closes 2nd fadeIn if-statement}
}
//Closes 1st fadeIn if-statement}
};
//Closes function
this.onEnterFrame = function() {
beatDuration = _root.beat.duration/1000;
beatPosition = _root.beat.position/1000;
fadeEnd = (beatDuration-5);
if (fadeEnd<=songPosition && beatVolume>0 && playing == true) {
if (beatVolume<=1) {
beatVolume = 0;
}
_root.beat.setVolume(beatVolume);
beatVolume = beatVolume-1;
}
};
Should anyone care to test this with their own sound file. Otherwise I will think further how to post this, when I am less tired and can think straight!
CyanBlue
04-24-2003, 03:51 AM
Um... I do not understand your question... :(
I see that your sample file is bigger than 100k... Why not put it up on your server or some place and let us know the URL so that people can download it... I think that is best way to let us know what you are trying to do... ;)
This is the script that I have modified yours... I have it to trigger the fade out when the song is at the end around 1 second or so... See if you can get some help with this one, I kinda doubt it though... Oh... Do not use multiple onEnterFrame handler... The second one was just killing the first one...beat = new Sound(this);
beat.attachSound("revival_b");
fadeIn01 = 1;
beat.start(0, 1);
beatVolume = 0;
beat.setVolume(beatVolume);
this.onEnterFrame = function()
{
//
//Fade In
//
trace("beat.getVolume() = " + beat.getVolume() + "\tbeat.duration = " + beat.duration + "\tbeat.position = " + beat.position);
beatDuration = _root.beat.duration / 1000;
beatPosition = _root.beat.position / 1000;
fadeEnd = (beatDuration - 5);
if (fadeIn01 == 1)
{
// fadeIn01 can be set to 1 when a button is
// pressed, when a frame is reached or many other ways.
_root.beat.setVolume(beatVolume);
// Sets the volume for the sound object "beat"
// to the variable "beatVolume" every time the
// frame is entered during the movie clip loop.
beatVolume = beatVolume + 5;
// Increments the variable "beatVolume" by 5.
// Increase or decrease this to change the speed of
// the fade from 0 to 100.
if (beatVolume > 30)
{
fadeIn01 = 0;
// This stops the "beatVolume" from incrementing
// by making the if-statement false once the volume
// reaches 30%.
}
//Closes 2nd fadeIn if-statement}
}
// if (fadeEnd <= songPosition && beatVolume > 0 && playing == true)
if (beat.duration - beat.position < 1000)
{
trace("\t\t1 second or less left...");
if (beatVolume <= 1)
{
beatVolume = 0;
}
_root.beat.setVolume(beatVolume);
beatVolume = beatVolume - 5;
}
};
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.