PDA

View Full Version : sound, Left and right speaker



AirWolf
February 10th, 2005, 11:05 AM
Hi Kirupa Admins!
I need some help to make a bar that controlls the sound that comes out from ether the righ tor the left speaker so If the bar is 100% left the the right speaker doesnt play any sound but the left is playing to 100%! (just like your "volume bar" tutorial but I need a Tutorial for right/left sound!

Thank you!
/AirWolf

tofuisonmyside
February 10th, 2005, 11:56 AM
hi airwolf,

Welcome on boards,

you could use the same code and change the volume by a pan variable and the setVolume by setPan; you certainly have to make some calculations because volume goes from 0 to 100 and pan from -100 to +100, on the line:
ratio = Math.round(this._x*100/line._width);

i let this to your sagacity right now, ok ?


my_sound.setPan(pan:Number) : Number

Parameters
pan An integer specifying the left-right balance for a sound. The range of valid values is -100 to 100, where -100 uses only the left channel, 100 uses only the right channel, and 0 balances the sound evenly between the two channels.

hope this helps you to start.
tofu.

AirWolf
February 11th, 2005, 03:21 PM
hi again! I cant make it work, "my_sound" is called "opening.mp3" in the libary (should ".mp3" be in "my_sound aswell?). My example:

opening.setPan(-100);

and It doesnt work! :(

Thank you for your help and time!
/AirWolf

2nd day
February 11th, 2005, 03:50 PM
well, i guess you don't use actionscript to load/attach your sound to the movie... here's a way to do that:
-first you must have a .mp3 in your library (you can also load a external .mp3)
-go to your library, right-click the sound and select linkage
-check export for actionscript and export in first frame
-fill in the id in the identifier name, for instance sound
-now the real scripting:


var sound = new Sound();
sound.attachSound("sound");
sound.start();
sound.setPan(-100);

-this is it!

good luck :cowboy:

brainy
February 12th, 2005, 12:46 AM
AirWolf, you need to replace the .setVolume line from the original volume slider tutorial:

mySound.setVolume(_root.volume);
with .setPan as described by tofuisonmyside. The original tutorial explains the sound attachment and everything else involved...