Forum Topic: Dynamic volume sound?(AS2)

(106 views • 4 replies)

This topic is 1 page long.

<< < > >>
None

sasuke2910

Reply To Post Reply & Quote

Posted at: 5/10/09 08:57 PM

sasuke2910 LIGHT LEVEL 08

Sign-Up: 06/11/06

Posts: 1,658

Ok, so I wanted to make an sound effect effect so that a sound would fade out/in. So I imported/attached two songs.(song1, song2)

And I make some loops and setIntervals to fade them but it wouldn't work. Because I was going to have one sound fade out and another one fade in, in the background. So I tried using setVolume change the volumes of the songs.

But I thought when I read the flash help on setVolume that it said "Sets the volume for a Sound object."

But it actually says "Sets the volume for the Sound object."

So if I change the setVolume value it changes it for all of my sounds. But I only need it to change for one.

TL;TR:
sound1.start();
sound2.start();
sound1.setVolume(100)
sound2.setVolume(0)

That make both songs volume equal 0 I only want song 2 to equal 0

I think I found something that actionScript can't do O.o
BBS Signature

None

Headshot777

Reply To Post Reply & Quote

Posted at: 5/10/09 09:04 PM

Headshot777 LIGHT LEVEL 20

Sign-Up: 05/04/08

Posts: 2,934

Er... Doesn't Flash have a built-in Custom function that let's you fade sounds?

12

BBS Signature

None

Denvish

Reply To Post Reply & Quote

Posted at: 5/11/09 03:19 AM

Denvish DARK LEVEL 45

Sign-Up: 04/25/03

Posts: 16,238

When you attach each sound, you need to attach it to a new Movieclip if you want to be able to adjust its volume/pan independently of other sounds.

createEmptyMovieClip("SA",_root.getNextHighestDepth());
SFXA=new Sound(SA);
SFXA.attachSound("sound1");
createEmptyMovieClip("SB",_root.getNextHighestDepth());
SFXB=new Sound(SB);
SFXB.attachSound("sound2");

You should then be able to use SFXA.setVolume(0); and SFXB.setVolume(0); to adjust each sound

- - Flash - Music - Images - -

BBS Signature

None

Denvish

Reply To Post Reply & Quote

Posted at: 5/11/09 03:51 AM

Denvish DARK LEVEL 45

Sign-Up: 04/25/03

Posts: 16,238

At 5/11/09 03:19 AM, Denvish wrote: You should then be able to use SFXA.setVolume(0); and SFXB.setVolume(0); to adjust each sound

In terms of fading in or out, something like this should work:

function FADEMUSIC(snd,io){																	//SOUND, INOUT
	clearInterval(fm);																					//CLEAR INTERVAL
	if(io){																									//FADE IN	
		fm=setInterval(function(){																	//INTERVAL
			if(snd.getVolume()<100){																//NOT TOO LOUD
				snd.setVolume(snd.getVolume()+1);											//VOLUME UP
			}else{																							//ENOUGH
				snd.setVolume(100);clearInterval(fm);										//CLEAR
			}																									//
		},100);																								//MS
	}else{																									//FADE OUT										
		fm=setInterval(function(){																	//INTERVAL
			if(snd.getVolume()>0){																	//STILL GOING DOWN
				snd.setVolume(snd.getVolume()-2);											//DOWN
			}else{																							//ZERO
				snd.setVolume(0);clearInterval(fm);											//CLEAR
			}																									//
		},100);																								//MS
	}																											//
}																												//

The snd parameter for the function in this case would be either SFXA or SFXB, and the io would be either 1 (fade in) or 0 (fade out). For example, to fade in sound1:

_root.FADEMUSIC(SFXA,1);

- - Flash - Music - Images - -

BBS Signature

None

Yambanshee

Reply To Post Reply & Quote

Posted at: 5/11/09 07:17 AM

Yambanshee DARK LEVEL 10

Sign-Up: 10/05/08

Posts: 1,450

of course there is the non dynamic way of changing the settings on the frame... but im guessing u want dynamism?

AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 03:28 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!