11 Replies Latest reply on Sep 27, 2013 11:47 AM by kglad

    Volume Slider with several audio files

    I designer

      How to create slider which will include more than 1 audio files.Am using this code for button to continue it till 3-4 scenes ahade-

       

      stop();

       

      mySoundBtn1.onRelease = function () {

       

                mySoundC = new Sound(this);

       

                mySoundC.attachSound("mySoundClip1");

       

                mySoundC.start(0, 10);  //10 represents the number of loops

       

                gotoAndPlay("play1", "abc");

       

      }

       

      This code is working for audio(audio play properly).But on second screen there is volume slider which do not get link from this code.Myproblem is

      I want to make code which will play audio after click on button and it should have facility that user can adjust this sound with volume slider.

      Can any one tell me perfect code to make this possible?Is there any more code to play sound and play continously for button.Am using as 2 in flash cs 5.

        • 1. Re: Volume Slider with several audio files
          kglad Adobe Community Professional & MVP

          create new sounds using different movieclips to control different sounds:

           

          stop();

           

          mySoundBtn1.onRelease = function () {

          var mySoundC_mc:MovieClip=this.createEmptyMovieClip(...); // likewise for other sounds

                    mySoundC = new Sound(mySoundC_mc);

           

                    mySoundC.attachSound("mySoundClip1");

           

                    mySoundC.start(0, 10);  //10 represents the number of loops

           

                    gotoAndPlay("play1", "abc");

           

          }

          1 person found this helpful
          • 2. Re: Volume Slider with several audio files
            I designer Level 1

            Thnx kglad.

            In the given code (mySoundClip1)it is the audio file.then

            var mySoundC_mc:MovieClip=this.createEmptyMovieClip(); // likewise for other sounds

                      mySoundC = new Sound(mySoundC_mc);

            does this code works for several file?how to attach sound here?how this code will work?I want to work buttons as like if else.

            If button 1 click a then sound is diffrent and again if btn 1 click b then audio should be diffrent.

             

            • 3. Re: Volume Slider with several audio files
              kglad Adobe Community Professional & MVP

              the key point is you must use different movieclips to control different sounds.

               

              eg, if you have 10 movieclip buttons (mySoundBtn1, ..., mySoundBtn10) and 10 sounds (with linkage id's mySoundClip1, ..., mySoundClip10) and you want each button to play the obvious sound, you can use:

               

              for(var i:Number=1;i<=10;i++){

              var mc:MovieClip=this["mySoundBtn"+i].createEmptyMovieClip("mc",0);

              this["mySoundBtn"+i].sound=new Sound(mc);

              this["mySoundBtn"+i].sound.attachSound("mySoundClip"+i);

              this["mySoundBtn"+i].onRelease=function(){

              this.sound.start(0,10);

              }

              }

              • 4. Re: Volume Slider with several audio files
                I designer Level 1

                Thnx kglad it was really helpfull.Thnx a lot!

                • 5. Re: Volume Slider with several audio files
                  kglad Adobe Community Professional & MVP

                  you're welcome.

                  • 6. Re: Volume Slider with several audio files
                    I designer Level 1

                    Hey kglad,

                    am here again.this,code works perfect thnx a lot but,it does'nt get any relation with volume slider.Can you plese help me some more?

                    I have done slider with this code.it drag the handle to right-left.but,it dosent effect with sound.Or can you suggest me any volume slider,which will get link from button and allows user to adjust volume as per his choise?

                    Here is a code,which i used.

                    onClipEvent (load) {

                        mySound2 = new Sound();

                        mySound2.loadSound((myScale)+"/"+(myTaal)+"/"+(myTaalPitch+myTaalLaya)+".ark", true);

                        mySound2.onSoundComplete = function() {

                        mySound2.start(0.058,999);

                    }

                    }

                    onClipEvent (enterFrame) {

                        downloaded = mySound2.getBytesLoaded();

                        total = mySound2.getBytesTotal();

                        if (downloaded != total) {

                            _root.d2 = "You have to buy this software...";

                        } else {

                            complete = 1;

                            _root.d2 = "";

                        }

                        mySound2.setVolume(ratio2 * 2);

                    }

                     

                     

                    and button has this code.

                    on (rollOver) {

                        mySound2 = new Sound();

                        mySound2.loadSound((myScale)+"/"+(myTaal)+"/"+(myTaalLaya)+"High1.ark", true);

                        mySound2.onSoundComplete = function() {

                        mySound2.start(0.058,999);

                    }

                    }

                     

                    /*on (rollOut) {

                        stopAllSounds();

                    }

                    */

                    on (release) {

                        gotoAndPlay("play3");

                        _global.myTaalLaya = "Low1";

                    }

                    adaDrutv83.onRelease = function () {

                     

                              mySoundC = new Sound(this);

                     

                              mySoundC.attachSound("adaDrutv83");

                     

                              mySoundC.start(0, 99);  //10 represents the number of loops

                     

                             gotoAndPlay("play3");

                     

                     

                    }

                     

                    adaDrutv83 is a button name and for second adaDrutv83 is a sound name.There are more than 100 buttons with diffrent sound,so i cant create separet volume slider for each button.Can you suggest anything?

                    Thnx in advance.

                    • 7. Re: Volume Slider with several audio files
                      kglad Adobe Community Professional & MVP

                      that's no really good coding.  to start, you should not attach code to any objects.  ie, all your on(whatever), onClipEvent(whatever) code should be replaced by code that attaches to frames, not objects.

                       

                      and i see one sound, mySoundC which is probably a poor choice for a name because with 100 sounds there may be no easy way to iterate through them all unless they're all added to an array.

                      • 8. Re: Volume Slider with several audio files
                        I designer Level 1

                        Thnx,

                        Yes,this attach sound code is applied on frames which has button (adaDrutv83) and also on button,because if i remove this code then,sound does'nt play.The code has little diffrance.

                         

                        On frame it is-

                        stop();

                         

                        adaDrut11.onRelease = function () {

                         

                                  mySoundC = new Sound(this);

                         

                                  mySoundC.attachSound("adaDrut11");

                         

                                  mySoundC.start(0, 99);  //10 represents the number of loops

                         

                                 gotoAndPlay("play3");

                               

                         

                        }

                         

                        And on button it is-

                         

                        on (rollOver) {

                            mySound2 = new Sound();

                            mySound2.loadSound((myScale)+"/"+(myTaal)+"/"+(myTaalLaya)+"High1.ark", true);

                            mySound2.onSoundComplete = function() {

                            mySound2.start(0.058,999);

                        }

                        }

                         

                         

                        /*on (rollOut) {

                            stopAllSounds();

                        }

                        */

                         

                        on (release) {

                            gotoAndPlay("play4");

                            _global.myTaalLaya = "Low1";

                        }

                        adaDrut11.onRelease = function () {

                         

                                  mySoundC = new Sound(this);

                         

                                  mySoundC.attachSound("adaDrut11");

                         

                                  mySoundC.start(0, 99);  //10 represents the number of loops

                         

                                 gotoAndPlay("play3");

                               

                         

                        }

                         

                        it is applied because i want to continue sound till last frame of my work.

                        I found some refrance for volume slider,which works,but it plays single sound at a time(I able to apply only 1 sound file).and i want to apply volume slider for more than 100 buttons.But,for that i can't create separet volume slider screen for each button.I know it,is a wrong method.

                        If i use the code which you,provide as if ,else then will it help to create single volume slider for all buttons?what will be the code?

                        You have provide this code-

                        for(var i:Number=1;i<=10;i++){

                        var mc:MovieClip=this["mySoundBtn"+i].createEmptyMovieClip("mc",0);

                        this["mySoundBtn"+i].sound=new Sound(mc);

                        this["mySoundBtn"+i].sound.attachSound("mySoundClip"+i);

                        this["mySoundBtn"+i].onRelease=function(){

                        this.sound.start(0,10);

                        }

                        }

                        • 9. Re: Volume Slider with several audio files
                          kglad Adobe Community Professional & MVP

                          you can use any slider to easily assign volumes to all your sounds, if you use the code i suggested:

                           

                          function volF(n:Number):Void{

                          for(var i:Number=1;i<=10;i++){

                          this["mySoundBtn"+i].sound.setVolume(n);

                          }

                          }

                          • 10. Re: Volume Slider with several audio files
                            I designer Level 1

                            Thnx kglad,but this code is not working.It plays sound but slider is not working.I have applied it on slider

                            • 11. Re: Volume Slider with several audio files
                              kglad Adobe Community Professional & MVP

                              what do the following trace statements show:

                               

                              function volF(n:Number):Void{

                              trace("volF "+n);

                              for(var i:Number=1;i<=10;i++){

                              this["mySoundBtn"+i].sound.setVolume(n);

                              trace(i+" "+this["mySoundBtn"+i].sound);

                              }

                              }

                              1 person found this helpful