Home Tutorials Forums Articles Blogs Movies Library Employment Press

<< Prev 5 | Next 5

Example of how to fade sound in

Follows is an example of how to fade sound in. We'll be using the sound object and placing everything inside an MC.
Basically the way this works is, we set up the sound object in frame 1 of our sound MC, then we use the set volume method of the sound object to gradually increase the sound:
1) Insert/New Symbol/Movie. You should now be in the MC's editing mode.
2) Frame 1 add the script:
stop ();
s = new Sound(this);
s.attachSound("mySound");
s.setVolume(0 );
3) Now add the scripts at 5 frame intervals to gradually increase the sound:
//frame5:
s.setVolume(10 );
//frame10:
s.setVolume(20 );
//frame15:
s.setVolume(30 );
//frame20:
s.setVolume(40 );
//frame25:
s.setVolume(50 );
//frame30:
s.setVolume(60 );
//frame35:
s.setVolume(70 );
//frame40:
s.setVolume(80 );
//frame45:
s.setVolume(90 );
//frame50:
s.setVolume(100 );
4) Finally place your start and stop buttons in your sound MC:
//Start button:
on (release) {
        s.start(0,10);
        play ();
}
//Stop button:
on (release) {
        s.stop();
        gotoAndStop (1);
}
You could also put the volume increments in a loop but I always have conflicts doing it that way.
Posted by: No name | website http://
fade in sound (MX)
//**********************************************
// create Sound obj and set volume at 0
//**********************************************
sndObj = new Sound();
sndObj.attachSound("loop");
sndObj.setVolume(0);
//**********************************************
// function to fade in the sound
//**********************************************
function fadeSnd(speed) {
        this.onEnterFrame = function() {
                vol += speed;
                if (sndObj.getVolume() == 100) {
                        //trace("sound at max!");
                        delete this.onEnterFrame;
                } else {
                        sndObj.setVolume(vol);
                        // show the fade
                        display = sndObj.getVolume();
                }
        };
}
//**********************************************
// button to activate snd and fadeSnd function
//**********************************************
sndBtnOn_mc.onPress = function() {
        sndObj.start(0, 9999);
        fadeSnd(1);
};
//**********************************************

Posted by: Martin Bjeld | website http://www.coolwebsites.dk
Fade sound
//Place the following in frame one:


var intervalID;
//**********************************************
// Set max and min volume levels.
//**********************************************
maxlevel = 100;
minlevel = 20;

//**********************************************
// Set Fade speed
// The higher the number, the longer the fade.
//**********************************************
fadespeed = 20;

//**********************************************
// create Sound object and attach a linked sound
//**********************************************
s = new Sound();
s.attachSound("loop");

function fadeup() {
        clearInterval(intervalID);
        intervalID = setInterval( upOne, fadespeed);
}

function fadedown() {
        clearInterval(intervalID);
        intervalID = setInterval( downOne, fadespeed);
}


// BUMP VOLUME UP
function upOne(){
        varSnd=s.getVolume();
        if (varSnd < maxlevel){
                s.setVolume(varSnd+1);
        }else{
                clearInterval(intervalID);
        }
        updateAfterEvent();
}
// BUMP VOLUME DOWN
function downOne(){
        varSnd=s.getVolume();
        if (varSnd > minlevel){
                s.setVolume(varSnd-1);
        }else{
                clearInterval(intervalID);
        }
        updateAfterEvent();
}

//**********************************************
// Start your Sound
//**********************************************
s.start(0,100);


//////////////////////////////////////////////////////////////


2) To call the functions, use the following code:

fadedown();

//or

fadeup();

Posted by: Michael Tapson | website http://www.tapsonic.com
Fading Sound 2
Method 1 was time consuming, you have to make all those frame and placing s.setVolume(10);, s.setVolume(20);, etc. So I decided to make it fade in using actionscripts. Lets get started!

1) Insert/New Symbol/Movie. You should now be in the MC's editing mode.
2) Frame 1 add the script:
s = new Sound(this);
s.attachSound("mySound");
s.setVolume(0);
s.start(0, 9999);
3) Frame 2 add this script:
s.setVolume(s.getVolume += 1)
4) Frame 3 add this script:
if(s.getVolume == 100) {
        gotoAndStop(4);
} else {
        gotoAndPlay(2);
}
5) Frame 4 add a blank frame and your done! Test it out, it should fade in accurtaely! Of course, you can make it fade out also if you wish to.
Posted by: Minh Luu | website http://bio.barrierx.com/
Fading Sound 3
1) Insert/New Symbol/Movie
2) In Frame 1, add the script:
vol = _root.s.getVolume(); 
_root.s.setVolume(vol-1); 
if (_root.s.getVolume() == 0) { 
_root.s.stop(); 
}
3) In Frame 2, add:

gotoAndPlay (1);
That is it.
Posted by: Mikke Schirén | website http://www.fororten.com

<< Prev 5 | Next 5

Copyright 2000-2010 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.