Skip to main content
September 17, 2013
Answered

Volume Slider with several audio files

  • September 17, 2013
  • 1 reply
  • 1940 views

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.

This topic has been closed for replies.
Correct answer kglad

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);

}

}

1 reply

kglad
Community Expert
September 17, 2013

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");

}

September 19, 2013

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.

September 27, 2013

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.


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);

}

}