A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: Fading In and Out

  1. #1
    Junior Member
    Join Date
    Aug 2006
    Posts
    12

    Fading In and Out

    Sorry I keep asking so many questions, but how do you make a sound fade in or out? A code, and maybe even a screenshot, would be appreciated. Thanks,

    -Fyce

  2. #2
    Senior Member indogo's Avatar
    Join Date
    Dec 2005
    Posts
    282
    Well the basic volume control command is

    my_sound.setVolume(level);

    where 'level' is a number from 0 to 100 and
    'my_sound' is the sound object used to play the sound.....

    so usage will depend on how your sound is incorporated in your movie and fading in and out is achieved by altering the 'level' variable say in a loop.

    hope this helps

    mike

  3. #3
    Junior Member
    Join Date
    Aug 2006
    Posts
    12

    my_sound?

    Quote Originally Posted by indogo
    'my_sound' is the sound object used to play the sound.....
    Wait, so the 'my_sound' part is where we put the file name? Like, 'song.mp3', or something? What do we put in the 'my_sound' part?

    -Fyce

  4. #4
    Senior Member indogo's Avatar
    Join Date
    Dec 2005
    Posts
    282
    Ok ..say for example you wanted to play a song in the same folder (streamed) you could use

    mySound = new Sound(); //creates a new sound object
    mySound.loadSound("song.mp3", true); //loads the file in streaming mode
    mySound.start(); //plays it

    so all control of the music is referenced by the 'mySound' part
    eg mySound.stop(); would stop the music

    'mySound' can be any name you choose and bear in mind flash 7 and later is case sensitive.

    hope this helps....takes a little while to sink in

    mike

  5. #5
    Junior Member
    Join Date
    Aug 2006
    Posts
    12

    Error

    Quote Originally Posted by indogo
    Ok ..say for example you wanted to play a song in the same folder (streamed) you could use

    mySound = new Sound(); //creates a new sound object
    mySound.loadSound("song.mp3", true); //loads the file in streaming mode
    mySound.start(); //plays it

    so all control of the music is referenced by the 'mySound' part
    eg mySound.stop(); would stop the music

    'mySound' can be any name you choose and bear in mind flash 7 and later is case sensitive.

    hope this helps....takes a little while to sink in

    mike
    I tried the first code, and it pops up an error message saying:

    "Line 1: expecting a , or )"

    On the mySound = new Sound(); part, do I put a filename in between the (), such as /Music/song.mp3, or just the song.mp3 part, or what? If you could give me a screenshot, that would be awesome!

    -Fyce
    Last edited by Fyce; 08-13-2006 at 10:46 PM.

  6. #6
    Senior Member
    Join Date
    Feb 2004
    Location
    Halifax, MA
    Posts
    205
    Quote Originally Posted by indogo
    hope this helps....takes a little while to sink in
    mike
    Mike, that is the most succinct and clear explanation I've seen. Or maybe I am finally getting my head around Actionscript enough to grasp it. If I ever start my KM wiki, that paragraph go in page one of Audio. Thanks.

  7. #7
    Senior Member
    Join Date
    Feb 2004
    Location
    Halifax, MA
    Posts
    205
    Quote Originally Posted by Fyce
    I tried the first code, and it pops up an error message saying:

    "Line 1: expecting a , or )"

    Fyce,
    I just cut and pasted Mike's code into the first frame of a blank movie. I saved it into a folder that contained an mp3 that I had renamed as "song.mp3" to go with the code. Then I ran it in a browser and after a moment heard the sweet voice of Doris Day. Try cutting and pasting just this code part:

    Code:
    mySound = new Sound(); //creates a new sound object
    mySound.loadSound("song.mp3", true); //loads the file in streaming mode
    mySound.start(); //plays it
    It otta woik. (Or put the name of your mp3 within the quotes in line 2.)

  8. #8
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    Mike, that is the most succinct and clear explanation I've seen. Or maybe I am finally getting my head around Actionscript enough to grasp it.
    I'd say both are correct Jim Lookin good Mike

  9. #9
    Senior Member indogo's Avatar
    Join Date
    Dec 2005
    Posts
    282
    mySound = new Sound();
    just as is...check nothing extra has been picked up when copying...does happen..

    and is the code where jim describes?..use the movie 'overview/actionscript displayed' to check...is the best place to look when using code.

    This will also play other tunes as well as Doris Day....
    mike

  10. #10
    Senior Member
    Join Date
    Feb 2004
    Location
    Halifax, MA
    Posts
    205
    Quote Originally Posted by indogo
    mySound = new Sound();
    This will also play other tunes as well as Doris Day....
    mike
    For sure. The Andrews Sisters, too. Not to mention Ella...

  11. #11
    Relaxing tmoore935's Avatar
    Join Date
    Oct 2001
    Location
    colorado, usa
    Posts
    1,713
    Quote Originally Posted by Fyce
    Sorry I keep asking so many questions, but how do you make a sound fade in or out? A code, and maybe even a screenshot, would be appreciated. Thanks,
    -Fyce

    To fade in our out, you could put this into a movieclip . Then change the volume to 0 or 100 and change vol = vol - 1; to vol = vol =1; as needed for fade n or fade out



    onClipEvent(load){

    mySound = new Sound(); //creates a new sound object
    mySound.loadSound("3.mp3", true); //loads the file in streaming mode
    mySound.start(); //plays it
    var vol;
    vol = 100;
    volume = vol;
    mySound.setVolume(vol);

    }
    onClipEvent(enterFrame){
    vol = vol - 1;
    mySound.setVolume(vol);
    if (vol >= 99) {
    vol = 99;
    }
    else if (vol <= 0) {
    vol = 0;
    }
    }
    Any programming language is at its best before it is implemented and used.

  12. #12
    Senior Member indogo's Avatar
    Join Date
    Dec 2005
    Posts
    282
    Nicely rounded off

    Actionscript in bite sized chunks...thats what we serve in the koolmoves restaurant..

    We now have all the ingredients...we now gaze at the oven in antici...pation.

    mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center