Link to home
Start Free TrialLog in
Avatar of ForLoop5
ForLoop5Flag for United States of America

asked on

How can I mix 2 sound channels?

I would like to have 2 sound channels.  each sound channel has its own volume control.  There is also a control to pan between the 2 sound channels.  I have an example attached.  I am looking to add the ability to pan between the two sounds.   mix2.fla
var balbounds:Rectangle=new Rectangle(balgroove_mc.x, balgroove_mc.y, balgroove_mc.width, 1 );
Bal_mc.addEventListener(MouseEvent.MOUSE_DOWN, startdragvolumebb);
Bal_mc.addEventListener(MouseEvent.MOUSE_OUT, stopdrag);
function startdragvolumebb(myevent:MouseEvent):void{
	myevent.target.startDrag(false, balbounds);
}
Bal_mc.buttonMode=true;



var myvolumebounds:Rectangle=new Rectangle(volumegroove_mc.x, volumegroove_mc.y, 1, volumegroove_mc.height);
volume_mc.addEventListener(MouseEvent.MOUSE_DOWN, startdragvolume);
//volume_mc.addEventListener(MouseEvent.MOUSE_OUT, stopdrag);
volume_mc.addEventListener(MouseEvent.MOUSE_UP, stopdrag);
volume_mc.addEventListener(MouseEvent.MOUSE_OUT, stopdrag);

function startdragvolume(myevent:MouseEvent):void{
	myevent.target.startDrag(false, myvolumebounds);
}
function stopdrag(myevent:MouseEvent):void{
	myevent.target.stopDrag();
	}
	
	playbutton1.addEventListener(MouseEvent.CLICK,player1);
		function player1(event:MouseEvent){
			
var myChannel:SoundChannel;
var newSetting:SoundTransform = new SoundTransform();
var snd:Sound = new b1();
myChannel= snd.play(0,9999);

stage.addEventListener(Event.ENTER_FRAME, everyframe);
function everyframe(myevent:Event):void{
	var newvolume:Number = 1-((volume_mc.y-volumegroove_mc.y)/115);
	newSetting.volume=newvolume;
	myChannel.soundTransform=newSetting;
}
		}
		
		
		
		
		var myvolumebounds2:Rectangle=new Rectangle(volumegroove_mc2.x, volumegroove_mc2.y, 1, volumegroove_mc2.height);
volume_mc2.addEventListener(MouseEvent.MOUSE_DOWN, startdragvolume2);
volume_mc2.addEventListener(MouseEvent.MOUSE_UP, stopdrag);
volume_mc2.addEventListener(MouseEvent.MOUSE_OUT, stopdrag);

function startdragvolume2(myevent:MouseEvent):void{
	myevent.target.startDrag(false, myvolumebounds2);
}

	
	playbutton2.addEventListener(MouseEvent.CLICK,player2);
		function player2(event:MouseEvent){
			
var myChannel2:SoundChannel;
var newSetting2:SoundTransform = new SoundTransform();
var snd2:Sound = new b2();
myChannel2= snd2.play(0,9999);

stage.addEventListener(Event.ENTER_FRAME, everyframe2);
function everyframe2(myevent:Event):void{
	var newvolume2:Number = 1-((volume_mc2.y-volumegroove_mc2.y)/115);
	newSetting2.volume=newvolume2;
	myChannel2.soundTransform=newSetting2;
}
		}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of dgofman
dgofman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ForLoop5

ASKER

I may have asked the question wrong, sorry.   I would like to "fade" between the two sound channels.  so if the slider is all the way to the left it would play the sound 1 loud and sound 2 would be muted but when you slide the slider all the way to the right sound 1 would be muted and sound 2 would be loud.  
This is not  "pan"  that is volume control

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/SoundTransform.html#pan

The left-to-right panning of the sound, ranging from -1 (full pan left) to 1 (full pan right). A value of 0 represents no panning (balanced center between right and left).




Thanks.  The problem I am having is that I have individual volume controls for the sounds on the left and volume control for the sounds on the right.  But I would like the middle slider when all the way to the left play the sound 1 and when all the way to the right play sound 2
how about "individual volume controls" the values should be change?
ok