dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: HowTo make AutoFade function ????

  1. #1
    Senior Member fantasio's Avatar
    Join Date
    May 2000
    Location
    at the progress bar
    Posts
    409

    Cool

    Hi, I want to make an autofade function for a sound object.
    Means when i press a button the sound gradually fades out to nothing.
    My code looks like this right now:

    function fade() {
    for (var i=1; i<=100; i++) {
    s.setVolume(s.getVolume()-1);}}

    this works, but the loop is to fast of course to make audible changes to the sound.
    Now how can I put something in the function that makes it wait for some moments between any decrement.... ?

    Any help welcome

  2. #2
    Member
    Join Date
    Jan 2002
    Location
    Dallas, TX
    Posts
    47
    Here is some code that might help you out. It is dependant on your framerate, so you'll need to adjust to suit your needs....

    on the button:
    on(release) {
    _root.fadeSound = true;
    }

    on your _root:
    fadeSound = false;

    _root.onEnterFrame = function() {
    if (fadeSound) {
    s.setVolume(s.getVolume()-1);
    if (s.getVolume() == 0) {fadeSound = false;}
    }
    }



  3. #3
    Senior Member fantasio's Avatar
    Join Date
    May 2000
    Location
    at the progress bar
    Posts
    409

    Thanks, but I need it in a one frame movie

    I used this method before, and it worked, but I want to try out something different (would take to long to explain why)
    I don't know if something like this exists, but is there something like a "wait" function or can I build something with the "get timer" command ?????

  4. #4
    I have altered Colin Moock's time based movement code a little to adapt for your fade problem. It works.

    I have attached the sound from library on first frame.
    Then added these frame codes. Movie stops on first frame then with a button release plays the following frames.

    //CODE ON fRAME 2
    var soundPerSecond = 10; /*this is assuming sound will go down 10 units per second,change it to your liking*/
    var now = getTimer(); //current time
    var then = 0; //The time when last frame rendered
    var elapsed; //milliseconds between frame renders
    var numSeconds; //elapsed expressed in seconds
    var reducevolumeAmount; //amount to reduce per second
    var v; //current volume

    //CODE ON FRAME 3
    then = now;
    now = getTimer();
    elapsed = now-then;
    numSeconds = elapsed / 1000;
    reducevolumeAmount = soundPerSecond * numSeconds;
    v = s.getVolume();
    newVolume = v - reducevolumeAmount;
    if (newVolume <= 2){
    s.setVolume(0);
    }
    else{
    s.setVolume (newVolume) ;
    }

    //CODE ON FRAME 4
    gotoAndPlay(3);

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