
Код AS3:
package
{
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.Event;
import flash.media.SoundTransform;
/**
* ...
* @author FieryWall
*/
public class Sounds
{
//...
public var crash1:Sound;
public var crash2:Sound;
//...
//...
private var crash1S:SoundChannel;
private var crash2S:SoundChannel;
//...
public var musicVelume:Number;
public var soundVelume:Number;
public function Sounds()
{
//...
crash1 = new crash1_c();
crash2 = new crash2_c();
//...
musicVelume = 1;
soundVelume = 1;
}
public function play(sound:Sound, peak:int = 0):void //Играть звук, параметры "какой звук" и "Панорама"
{
var mt:SoundTransform = new SoundTransform();
var st:SoundTransform = new SoundTransform();
st.pan = peak;
mt.volume = musicVelume;
st.volume = soundVelume;
switch(sound){
//...
case crash1:crash1S = crash1.play(0, 1);
crash1S.soundTransform = st;
crash1S.addEventListener(Event.SOUND_COMPLETE, soundComplite); break;
case crash2:crash2S = crash2.play(0, 1);
crash2S.soundTransform = st;
crash2S.addEventListener(Event.SOUND_COMPLETE, soundComplite); break;
//...
}
}
public function stop(sound:Sound):void {//Остановить звук, параметр "какой звук"
switch(sound){
//...
case crash1:if (crash1S) {
crash1S.stop();
crash1S = null}
break;
case crash2:if (crash2S) {
crash2S.stop();
crash2S = null }
break;
//...
}
}
public function isPlaying(sound:Sound):Boolean { //Проверка на проигрование звука, параметр "какой звук"
switch(sound){
//...
case crash1:if (crash1S) {
return true } else {
return false }
break;
case crash2:if (crash2S) {
return true } else {
return false }
break;
//...
default:return false;
}
}
public function updateVelume(mv:Number, sv:Number):void { //Задание громкости звука, праметры "громкость музыки" и "громкость звука"
var mt:SoundTransform = new SoundTransform(mv);
var st:SoundTransform = new SoundTransform(sv);
musicVelume = mv; soundVelume = sv;
//...
if (crash1S) {
crash1S.soundTransform = st;
}
if (crash2S) {
crash2S.soundTransform = st;
}
//...
}
private function soundComplite(e:Event):void //Очистка каналов, параметр "конец воспроизведения"
{
//...
if (e.target === crash1S) { crash1S = null }
if (e.target === crash2S) { crash2S = null }
//...
}
}
}