dcsimg
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 29

Thread: [Resolved] fading sound

  1. #1
    Hi there, anybody can help me to solve this?
    I got a looping background music playing and when i click on a button, the background music will fade out and stop.

    is it possible? thanks in advance!

    cheers

  2. #2
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    if you can loaded the sound dynamically, using
    sound_variable = new Sound();
    you can use this code.
    Code:
    function fade() {
    	this.createEmptyMovieClip("mc", 1);
    	mc._x = 100;
    	this.onEnterFrame = function() {
    		mc._x += (0 - mc._x) / 50;
    		sound_variable.setVolume(mc._x);
    	};
    }
    On the button put this code;
    Code:
    on(release){
      _root.fade();
    }
    This works but there might be a shorter code

  3. #3
    hey EQFLASH, thanks again!
    but what do you mean by load sound dynamically? attach sound?

    your help is very much appreciated.
    cheers

  4. #4
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    loadSound
    but this code will work if you attachSound also

  5. #5
    Hi sorry to bother you again, but my code can't seem to work.

    I put the below code on the first frame of the main timeline
    ------------------------------------------------------------
    myMusic = new Sound();
    myMusic.attachSound("Loop");
    myMusic.start( 0, 1000 );




    function fade() {
    this.createEmptyMovieClip("mc", 1);
    mc._x = 100;
    this.onEnterFrame = function() {
    mc._x += (0 - mc._x) / 50;
    sound_variable.setVolume(mc._x);
    };
    }
    ------------------------------------------------------------

  6. #6
    Hi, the code finally works now.

    ----------------------------------------------
    myMusic = new Sound();
    myMusic.attachSound("Loop");
    myMusic.start( 0, 1000 );




    function fade() {
    this.createEmptyMovieClip("mc", 1);
    mc._x = 100;
    this.onEnterFrame = function() {
    mc._x += (0 - mc._x) / 50;
    myMusic.setVolume(mc._x);
    };
    }
    ---------------------------------------------------

    thanks!!

  7. #7

    it fades off all sounds

    Hi EQFlash,
    I got a problem here, i got one background sound and one voiceover in one swf file but when i click on a button to ask the background sound to fade off, i need the voiceover to stay.

    With the code that i have now when i click on the button, both sounds also fade off.

    i will really appreciate it if you can help, sorry for bothering you.

    thanks!

  8. #8
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    give the voice over a different variable.
    and you are not bothering me.
    this is we what we do here at the forum, we ask and answer
    [Edited by EQFlash on 08-15-2002 at 09:19 AM]

  9. #9
    Hi EQFLASH, could you show me how to set the voiceover to a different variable? I tried but it doesn't work.

    thanks!!

  10. #10
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    lets say you have 3 sound you want to control independently.
    each sound would have a different variable assigned to it.
    It is not the sound that is being controlled, it's the variable. so...
    Code:
    //Sound 1
    myMusic1 = new Sound();
    myMusic1.loadSound("sound1.mp3");
    myMusic1.start(0,1000);
    //Sound 2 
    myMusic2 = new Sound();
    myMusic2.loadSound("sound2.mp3");
    myMusic2.stop(0,1000);
    //Sound 3 
    myMusic3 = new Sound();
    myMusic3.loadSound("sound3.mp3");
    myMusic3.stop(0,1000);
    the above code assigns a different variable to each sound.
    when you want to control the volume of say, sound2.mp3, you would refer to it's variable. it also starts only the first sound i.e.
    Code:
    myMusic2.setVolume(40);
    this sets the volume of sound2.mp3 to 40 while leaving the other sounds at their own volumes. you would have to apply start buttons to play the other sounds.
    hope this helps

  11. #11
    Hi EQFLASH,
    what if one of my sound (voiceover) is in "stream" mode as i need to synchronise it with the animation?

    I will not be able to synchronise with the animation if i use the "loadsound" action right?

    thanks!

  12. #12
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    there is a way to do this using loadSound()
    you would have to know the beats per minute of the sound though.
    I could show you in a sample file if you like.

  13. #13
    Could you please show me the sample file?

    thanks
    ks

  14. #14
    Senior Member
    Join Date
    Apr 2002
    Posts
    682
    In addition, you might want to check out my tutorial on sound objects in the link in my sig.

  15. #15
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    Sorry bout that Kenny.I should have pointed your site out to kimseng

  16. #16
    Senior Member
    Join Date
    Jul 2001
    Location
    Planet Earth
    Posts
    298

    Fading with set and clear interval

    Not that I could ever match Flash wits with Kennyb or EQFlash but I was playing around with fading music myself.

    I am interested to see what you guys think of this code (unless you think it sucks ).

    Frame 1 -
    Code:
    song = new Sound();  // new sound object 
    song.attachSound("music"); //sound in the library exported to actionScript with name music
    song.start(); //get the groove going (play the sound)
    
    
    function fadeSound(){
    	if (song.getVolume() > 0){
    	song.setVolume(song.getVolume() - 10);
    	trace(song.getVolume());  // see values in output window
    	}
    	else {
    		clearInterval(counter);
    	}
    }
    On a button -
    Code:
    on (release){
    	counter = setInterval(_root.fadeSound, 500);
    }
    Comments?

  17. #17
    Thanks Kenny,
    your site is absolutely a big help for me to know more about sound in flash.

    I still got a question here to ask the experts like you all about synchronizing animation with sound.

    I got a character to be placed on the main timeline and the mouth will synchronize with the voiceover in "streaming mode". There is a looping background sound playing and when user clicks on a "mute background sound" button, the background sound will fade off and stop but the voiceover and the animation of the mouth will still playing.

    If i will have to use the "sound position" to do it then i think its kind of hassle for me to do the synchronization as i need to calculate the sound beats and also i need to "test movie" everytime to check whether they are synchronized properly becuase you will not hear the sound until you hit "test movie" right?

    well, I'm wondering whether this is the only way to do it, using sound position?

    Thanks a lot dude!
    cheers

  18. #18
    Senior Member
    Join Date
    Apr 2002
    Posts
    682
    It's fairly common to embed the sound in your movie and set it to streaming, you can simply locate the frame position and align your animation with the frame position.

    Just import the mp3 to your library, drop the sound on stage with a keyframe selected, add another keyframe corresponding to the end of the sound. Then, you can drag your mouse over the frames to hear the sound position.

    You don't have to use the position method, which can become bulky. It's just another way to do it. It's a nice way to do it if you need high accuracy.

  19. #19
    Kenny, Thanks for the reply, i actually did it that way in the begining as its the common way of doing the synchronization but it doesn't work if i want to fade off the background sound and keep the voiceover playing (stream mode) when a button is clicked.

    In the previous discussions with EQFLASH, in order to fade off the background sound when i click on a button, i need to put the background sound and the voiceover into 2 different variables, if not the voiceover and the background sound will fade off at the same time when the button is clicked.

  20. #20
    Senior Member
    Join Date
    Apr 2002
    Posts
    682
    Now that you understand both ways to do it, you can combine, mix-and-match to get the effect you need. For example, why not apply the sound object method to the background sound you need to fade and the embedded sound approach to the vocals?

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