A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: sound fade out on buttons

  1. #1
    Junior Member
    Join Date
    May 2003
    Posts
    18

    sound fade out on buttons

    I have sound attached to some buttons. ok it plays fine, but when i rollout the sound stops to abruptly it sounds terrible. How can i make it so the sound fades out for around 2 seconds instead of just stopping.

    My code:

    on (rollOver) {
    mysound = new Sound();
    mysound.attachsound("spooky");
    mysound.start(0,1);
    mysound.setVolume(100);
    }

    on (rollOut) {
    mysound.stop();
    }

    Your help is appreciated.
    If a stranger offers u a lift I say take it

  2. #2
    Flashkit Jedi

    Join Date
    Jul 2001
    Location
    Coruscant System
    Posts
    3,426
    On the root timeline, place this code:

    Code:
    fadespeed = 1;
    mysound = new Sound();
    mysound.attachsound("spooky");
    onEnterFrame = function(){
      if((fadeout)&&(mysound.getVolume() > 0)){
        mysound.setVolume(mysound.getVolume() - fadespeed);
        if(mysound.getVolume() <= 0){
          mysound.stop();
          mysound.setVolume(100);
          fadeout = false;
        }
      }
    }
    And in the button where your sound.stop action is at, replace with this code:

    Code:
    on(rollOver){
      mysound.start(0, 1);
    }
    on(rollOut){
      fadeout = true;
    }
    As far as I can see this should work.

    XFM

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