Skip to main content
dalvydasv27776233
Inspiring
November 7, 2016
Question

Change volume with mouse wheel

  • November 7, 2016
  • 2 replies
  • 326 views

Hey. I have script:

stage.addEventListener(MouseEvent.MOUSE_WHEEL, garsas);

var volumeAdjust:SoundTransform = new SoundTransform();

volumeAdjust.volume = 1;

function garsas(event:MouseEvent) {

var delta:int = -event.delta;

if(delta < 0){

        volUp();

}

if (delta > 0){

    volDwn();

    }

}

{

     volumeAdjust.volume += 0.05;

      if(volumeAdjust.volume > 1)

     {

          volumeAdjust.volume = 1;

     }

     soundTransform = volumeAdjust;

     }

function volDwn():void

{

     volumeAdjust.volume -= 0.05;

     if(volumeAdjust.volume < 0)

     {

          volumeAdjust.volume = 0;

     }

     soundTransform = volumeAdjust;

     }

This is script is working for me just one time. I mean if music starts play in the first frame its working. bet then a new sound starts the wolume is max and this script is not working any more. And i cant understad why? Can any one help ?

This topic has been closed for replies.

2 replies

dalvydasv27776233
Inspiring
November 7, 2016

Thank you for your help. I understand then music files in library and they have class names. BUT

OMG Im going crazzy. I dont know how many files i will have maby 20 maby 128455578455846965689. My some music files in folder others in library. When i go to for example to frame 5  flash uploading MP3 file from folder and plays. When i go to another frame flash uploads new song from folder all file names is different. Other short sounds for buttons i have in library,

One frame:

var sSuomija:Sound = new Sound();

sSuomija.load(new URLRequest("euro/1suomija.mp3"));

sSuomija.play();

Frame NO 5

var janina:Sound = new Sound();

janina.load(new URLRequest("euro/janina_degutyte_kainuojadaug.mp3"));

janina.play();

Frame NO 17

var kilo_gaisras.Sound = new Sound();

kilo_gaisras.load(new URLRequest("euro/buvogera_gaspadine.mp3"));

kilo_gaisras.play();

There is no solution for MASTER volume in flash? I mean volume for all sounds in the flash and where ever they are on library or uploaded from file.

kglad
Community Expert
Community Expert
November 7, 2016

correct.

kglad
Community Expert
Community Expert
November 7, 2016

remove your sound from the timeline, assign it a class in the library panel (eg, S1). you can then use:

var alreadyExecuted:Boolean;

if(!alreadyExecuted){

var s1:S1=new S1();

var sc:SoundChannel=s1.play(0,999);

stage.addEventListener(MouseEvent.MOUSE_WHEEL, garsas);

var volumeAdjust:SoundTransform = sc.soundTransform;

}

function garsas(event:MouseEvent) {

var delta:int = -event.delta;

if(delta < 0){

volUp();

}

if (delta > 0){

volDwn();

}

}

function volUp()

{

volumeAdjust.volume += 0.05;

if(volumeAdjust.volume > 1)

{

volumeAdjust.volume = 1;

}

sc.soundTransform = volumeAdjust;

}

function volDwn():void

{

volumeAdjust.volume -= 0.05;

if(volumeAdjust.volume < 0)

{

volumeAdjust.volume = 0;

}

sc.soundTransform = volumeAdjust;

}

dalvydasv27776233
Inspiring
November 7, 2016

But it works with one sound file S1. I have 20 song files and then new song start to play again I have loud volume. I need that then i set loud for ex. 0,5.. and allllll sound in the flash plays in 0,5. And then I want I can make it louder.

kglad
Community Expert
Community Expert
November 7, 2016

use:

var alreadyExecuted:Boolean;

if(!alreadyExecuted){

var numSounds=20;

var soundA:Array=[];

var index:int=0;

var sc:SoundChannel;

var st:SoundTransform=new SoundTransform();;

var C:Class;

for(var i:int=0;i<numSounds;i++){

C=Class(getDefinitionByName("S"+i));

soundA.push(new C());

}

stage.addEventListener(MouseEvent.MOUSE_WHEEL, garsas);

nextSoundF(null);

function nextSoundF(e:Event):void{

if(i<numSounds){

sc=soundA[index].play();

sc.addEventListener(Event.SOUND_COMPLETE,nextSoundF);

sc.soundTransform=st;

} else {

// end sounds.  restart?

}

i++;

}

function garsas(event:MouseEvent) {

var delta:int = -event.delta;

if(delta < 0){

volUp();

}

if (delta > 0){

volDwn();

}

}

function volUp()

{

st.volume += 0.05;

if(st.volume > 1)

{

st.volume = 1;

}

sc.soundTransform = st;

}

function volDwn():void

{

st.volume -= 0.05;

if(st.volume < 0)

{

st.volume = 0;

}

sc.soundTransform = st;

}