A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [F8] onrelease - fade out sound

  1. #1
    Senior Member
    Join Date
    Aug 2006
    Posts
    293

    [F8] onrelease - fade out sound

    morning all!

    need some help on something here if possible so am hoping that someone can tell me how to do the following.

    I have a number of mc's on my stage that can be clicked and dragged around - I want each mc to play one of four random sounds when clicked and dragged - but then I want the sound that is playing to fade out when the mouse is released. I have got it working with the stopallsounds function - but I would like the sounds to fade rather than stopping abruptly.

    here is my code
    Code:
    //create an array to hold all the sounds
    var sound_explosions_array:Array = Array();
    
    //create a sound object
    var explosion01_snd:Sound = new Sound();
    //attach sound from library
    explosion01_snd.attachSound("explosion01");
    //add sound to array
    sound_explosions_array.push(explosion01_snd);
    
    
    var explosion02_snd:Sound = new Sound();
    explosion02_snd.attachSound("explosion02");
    sound_explosions_array.push(explosion02_snd);
    
    var explosion03_snd:Sound = new Sound();
    explosion03_snd.attachSound("explosion03");
    sound_explosions_array.push(explosion03_snd);
    
    var explosion04_snd:Sound = new Sound();
    explosion04_snd.attachSound("explosion04");
    sound_explosions_array.push(explosion04_snd);
    
    //play random explosion
    function playExplosion():Void{
    	//get random number based on sound array length
    	var randomNum:Number = random(sound_explosions_array.length);
    	//create a temporary sound object
    	var random_sound:Sound = sound_explosions_array[randomNum];
    	//tell temporary sound object to play
    	random_sound.start();
    	//trace
    	currentSound_txt = "Playing Sound "+randomNum;
    }
    
    //make container_mc a button, play explosion sound on click
    container_mc.onPress = function(){
    	playExplosion();
    }
    container_mc.onRelease = function(){
    	StopAllSounds();
    }
    i guess this is the relevant line to edit

    Code:
    //make container_mc a button, play explosion sound on click
    container_mc.onPress = function(){
    	playExplosion();
    }
    container_mc.onRelease = function(){
    	Stopallsounds();
    }
    but how do i write that last line to make it fade??

    Anyone know? I have found a few bits n' bobs on the net - but they all seem to be for transitions of one sound to another - I don't need it to be quite so sophisticated, just a case of release mouse - sound fades.

    Anyone put me right on this please?

  2. #2
    Senior Member
    Join Date
    Sep 2007
    Location
    UK
    Posts
    194
    Maybe you can make use of this code, I lifted it from a template file and I think it does the same thing your asking for.

    PHP Code:
    onClipEvent (load) {
        
    _root.snd 100;
        
    cur _root.snd;
    }
    onClipEvent (enterFrame) {
        if (
    cur>_root.snd) {
            
    cur -= step;
        } else if (
    cur<_root.snd) {
            
    cur += step;
        }
        
    _root.globalsound.setVolume(cur);


  3. #3
    Senior Member
    Join Date
    Aug 2006
    Posts
    293
    ...cheers man - i'll see if i can suss it
    ;-)

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