Skip to main content
Participating Frequently
November 27, 2017
Answered

Adobe Animate - ActionScript 3.0 Volume Control Issue

  • November 27, 2017
  • 1 reply
  • 2105 views

Hello,
Currently I am having an issue figuring out how to get one button to control my audio. As a work-around, I'm using a slider, but I would love to have a single button controlling the volume of my audio. For a little more information, I am trying to get a single button to change the volume from 100%, to 50%, then to 25%, then to 0%, and back to 100%, while also changing the graphic used for each volume state. Any help would be greatly appreciated! Thanks!

This topic has been closed for replies.
Correct answer kglad

Looking at my question, I think I was confusing myself.

How would I go about making a single movie clip (to function as the button) and change graphics in the movie clip?


the same:

var sc:SoundChannel = strife.play();

var voltransform:SoundTransform = new SoundTransform();

var volA:Array = [.50,.25,0,1.00];

var index:int = 0;

your_button.addEventListener(MouseEvent.CLICK, clickF);

function clickF(e:MouseEvent):void{

setVolume(volA[index]);

index=(index+1)%volA.length;

index=(index+1)%volA.length;

setGraphicF(index+1);

}

function setVolume(vol){

    volTransform.volume = vol;

    SoundMixer.soundTransform = volTransform;

}

function setGraphic(n:int):void{

your_button.gotoAndStop(n);

}

1 reply

kglad
Community Expert
Community Expert
November 27, 2017

what code are you using that's not working?

YukiDrawsAuthor
Participating Frequently
November 27, 2017

Hi!

Right now I'm using this code:

import flash.media.Sound;

import flash.media.SoundChannel;

import flash.media.SoundTransform;

import fl.events.SliderEvent;

Slider.visible = false;

Max_btn.Mute_btn.visible = false;

var s:Sound = new Sound();

var strife:Strife = new Strife();

var sc:SoundChannel = strife.play();

function setVolume(vol){

    var volTransform:SoundTransform = new SoundTransform();

    volTransform.volume = vol;

    SoundMixer.soundTransform = volTransform;

}

var voltransform:SoundTransform = new SoundTransform();

Slider.addEventListener(SliderEvent.THUMB_DRAG,changevol);

function changevol(event:SliderEvent):void{

    voltransform.volume = Slider.value;

    SoundMixer.soundTransform = voltransform

}

var Slider_control:Boolean = false;

Max_btn.addEventListener(MouseEvent.CLICK, toggleSlider_control);

function toggleSlider_control(event:MouseEvent){if(Slider_control == true){Slider_control = false;

    Slider.visible = false;

    }

    else{Slider_control = true;

        Slider.visible = true;

    }

}

That's not what I want to use though, I'd like to have it be a single button that doesn't bring up a slider, and instead changes the volume multiple levels. I've tried using an "if else..." statement, but that only takes the first bit I give it, and won't go back. I can make it a toggle button for "on off", but that isn't what I want either.

kglad
Community Expert
Community Expert
November 27, 2017

var sc:SoundChannel = strife.play();

var voltransform:SoundTransform = new SoundTransform();

var volA:Array = [50,25,0,100];

var index:int = 0;

your_button.addEventListener(MouseEvent.CLICK, clickF);

function clickF(e:MouseEvent):void{

setVolume(volA[index]);

index=(index+1)%volA.length;

}

function setVolume(vol){

    volTransform.volume = vol;

    SoundMixer.soundTransform = volTransform;

}