A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: fading out sounds with a button

  1. #1
    Junior Member
    Join Date
    Aug 2001
    Posts
    14
    hey i was wondering if there was any particular code to fade out sounds with the press of a button within the movie, also i was wondering if you can fade sound in once and then have it loop contiunesly at the normal sound volume...if someone can get back to me that would be great...
    thanks

  2. #2
    Senior Member
    Join Date
    Apr 2002
    Posts
    682
    The easiest way to do this is with Sound Objects, which include a setVolume option that can be driven by a variable.

    buttonone=new Sound();
    buttonone.attachSound("button01");
    buttonone.SetVolume(100);

    Here's a way to fade using Sound Objects:

    When you press your button:

    on(press) {soundfade=1}
    //
    Then on a movieclip that loops:

    onClipEvent (load) {
    _global.i = 75;
    s = new Sound();
    s.setVolume(i);
    }
    onClipEvent (enterFrame) {
    if (soundfade==1) {
    S.setVolume(i);
    _global.i--;
    }

    The following is a mini-tutorial I wrote for someone else on using sound objects. It might help you.

    1. Locate each of the three sounds in your library and right click them.
    2. Select "Linkage" then select "Export for Actionscript."
    3. In the window that will then appear, enter an ID for the sound, e.g., buttonsound01. For the next, use buttonsound02, etc.
    4. You need to define the sound object before you can use them in your buttons. To do this, create an empty movieclip and drag it out on stage.
    5. In the first frame of this mc, type:

    buttonone=new Sound();
    buttonone.attachSound("button01");
    buttonone.SetVolume(100);
    //
    buttontwo=new Sound();
    buttontwo.attachSound("button02");
    buttontwo.SetVolume(100);
    //
    Similar for button 3.

    Then, when you want to activate these sounds:

    on(press) {
    _root.buttonone.start();
    }

    And if you need to stop a sound for some reason:

    _root.buttonone.stop("button01");



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