Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Adobe Animate - ActionScript 3.0 Volume Control Issue

New Here ,
Nov 27, 2017 Nov 27, 2017

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!

TOPICS
ActionScript
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 27, 2017 Nov 27, 2017

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

...
Translate
Community Expert ,
Nov 27, 2017 Nov 27, 2017

what code are you using that's not working?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 27, 2017 Nov 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 27, 2017 Nov 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;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 27, 2017 Nov 27, 2017

Inserting that code gives me an "Access of undefined property volTransform" error.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 27, 2017 Nov 27, 2017

use voltransform

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 27, 2017 Nov 27, 2017

I've gotten the code to play nice with my existing code, removed the slider portion of the code, so that works now. Now my audio starts normally, but when I click the button, it cycles between ear-rape, slightly less ear-rape, and mute. Is there also a way to change the graphic to correspond to the volume level?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 27, 2017 Nov 27, 2017

oops, that's my fault.  use:

var volA:Array = [.5,.25,0,1.];

and yes, you can change a graphic.  you just have to decide how you want to do that.  eg, change movieclip frames, use different images,something else?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 27, 2017 Nov 27, 2017

Nice! That worked wonders! Thank you so much!

For my previous project, I used a button that had a mute symbol inside a movieclip, and I hid and revealed that part of it. Not the most ideal way of doing it, but how would I go about changing the graphic so that previous graphics hide, while keeping it clickable?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 27, 2017 Nov 27, 2017

any shape with an alpha of 0 is clickable and not visible.

but you probably want to display 4 graphics on 4 different keyframes with that approach.  the easiest way to set that up is to put the 100% volume on frame 1, the 50% volume on frame 2, the 25% on frame 3 and the mute on frame 4. put a stop() on frame 1.

you could then use:

function clickF(e:MouseEvent):void{

setVolume(volA[index]);

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

setGraphicF(index+1);

}

function setGraphic(n:int):void{

your graphicmovieclip.gotoAndStop(n);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 27, 2017 Nov 27, 2017

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 27, 2017 Nov 27, 2017

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

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 27, 2017 Nov 27, 2017

I'm getting a "TypeError: Error #1010: A term is undefined and has no properties. at Test_Project_fla::MainTimeline/frame1()". And when I test the animation, it doesn't progress past the first frame, but my volume button switches between all of it's frames in a loop.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 27, 2017 Nov 27, 2017

oops, that volTransform needs to be voltransform again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 27, 2017 Nov 27, 2017

It still seems to be doing that. :T

Edit: It seems I made a goof, and the way I made my movie clip was weird.

Edit 2: It works! Thank you so much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 27, 2017 Nov 27, 2017
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines