How would someone change sound levels of a music playing in a loop? For example, I'm making a game and at a certain frame I want the music level (music.wav) to be decreased to half of its volume.
How could someone do this in AS3?
How would someone change sound levels of a music playing in a loop? For example, I'm making a game and at a certain frame I want the music level (music.wav) to be decreased to half of its volume.
How could someone do this in AS3?
Copyright © 2021 Jogjafile Inc.
You are using the word "loop" in a confusing way. In programming, a loop usually refers to one of the "for" loops that looks like this:
I surmise that this is not what you mean by loop, but rather that you would like a
MovieClipor the main timeline to decrease the volume of aSoundobject at the end ofnframes. Or do you just mean the music itself is looping? Hopefully you see the value of asking well written questions. That being said..Mind you, I haven't tried this, but according to my reference book (ActionScript 3.0 Cookbook by Lott, Schall & Peters) you need to use a
SoundTransformobject which specifies the volume at which you want the sound to be set. Try this:Now in your loop (or on the frame event that you are using) do this:
So anytime you want the volume to decrease by this incremental amount, run this bit of code. Of course, you need to make sure that any variables you set are accessible in the code that is referencing them. One way that comes to mind to do this is with a function.
Now, whenever you want to diminish the volume just call the
soundDiminishfunction.Maybe your frame event looks like this:
If you only want this function to be called every 20 frames then: