Sound Crossfader Question
I am making a cross fader for a flash program I am making. I want it to smoothly switch between two songs that are playing. When the slider is all the way to the left sound1 is playing at 100% volume and sound2 is at 0% volume, when the slider is on the right the are switched and when its in the middle they both play at 50%, with a smooth transition in between. I set up all the code just like in the volume slider tutorial on this site with the exception of two Sound objects, leftSound and rightSound, instead of one, and I removed the stop and play buttons. I then set the volume function with this code:
slider.slideBar.onEnterFrame = function() {
leftSound.setVolume(50-((this._x)/5));
rightSound.setVolume(50+((this._x)/5));
}
according to all my calculations this is correct. I entered the functions in my calculator to make sure they were correct for each value of x and they were…(the scene is 550px wide and the sliderbar is 50 px wide which is why this._x is divided by 5 to get 100)
Now the problem that occurs is when I test the movie both sounds take on the same volume. When the slider is on the left both sounds are mute but when it’s on the right both songs are 100% volume. And I have no clue why flash does this. Does anyone have any clue as to what is going on here.
Here is my complete ActionScript:
leftSound = new Sound(this);
rightSound = new Sound(this);
leftSound.attachSound("sound1");
rightSound.attachSound("sound2");
leftSound.start(0, 99);
rightSound.start(0, 99);
slider.slideBar._x = -250;
slider.slideBar.onEnterFrame = function() {
leftSound.setVolume(50-((this._x)/5));
rightSound.setVolume(50+((this._x)/5));
}
slider.slideBar.onPress = function() {
startDrag(this, false, -250, this._y, 250, this._y);
}
slider.slideBar.onRelease = slider.slideBar.onReleaseOutside=function () {
stopDrag();
}
stop();
I am completely stumped as to why this is happening, any help would be greatly appreciated.
|