I’m trying to set the sound to mute by default and I’m not sure how to do it. Any help would be appreciated. thanks. here is the code for my MP3 player
package com.utils
{
import flash.display.Sprite;
import flash.events.;
import flash.media.Sound;
import flash.media.;
import flash.media.SoundTransform;
import flash.media.SoundChannel;
import flash.net.*;
import flash.utils.Timer;
import caurina.transitions.Tweener;
public class Mp3Player extends Sound {
private static var firstPlayed:Boolean = true;
private static var fadeOutIncr = 1;
private static var music:Sound;
private static var channel:SoundChannel;
private static var _link:String;
public static var _mute:Boolean = false;
private static var sAmbienceVol:SoundTransform = new SoundTransform(1, 0);
public function Mp3Player()
{
}
public static function getLink (link:String)
{
_link = link;
if ((firstPlayed == false) && (_mute == false)) setFadeOutTimer();
else playSound();
firstPlayed = false;
}
private static function playSound():void
{
music = null;
music = new Sound (new URLRequest(_link));
loop();
}
private static function loop(e:Event = null) {
if (channel != null) {
channel.stop();
channel.removeEventListener(Event.SOUND_COMPLETE, loop);
}
channel = music.play();
channel.soundTransform = sAmbienceVol;
channel.addEventListener(Event.SOUND_COMPLETE, loop);
}
private static function setFadeOutTimer():void
{
var soundFadeInTimer:Timer = new Timer(100,10);
soundFadeInTimer.addEventListener("timer", soundFadeOut);
soundFadeInTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerFadeOutComplete);
soundFadeInTimer.start();
}
private static function soundFadeOut(e:TimerEvent)
{
fadeOutIncr -= 1/10;
sAmbienceVol = new SoundTransform(fadeOutIncr, 0);
channel.soundTransform = sAmbienceVol;
}
private static function timerFadeOutComplete(e:TimerEvent)
{
if (_mute) fadeOutIncr = 0;
else fadeOutIncr = 1;
sAmbienceVol = new SoundTransform(fadeOutIncr, 0);
playSound();
}
public static function mute()
{
var soundFadeInTimer:Timer = new Timer(100,10);
soundFadeInTimer.addEventListener("timer", soundFadeOut);
soundFadeInTimer.start();
_mute = true;
}
public static function unmute()
{
var soundFadeInTimer:Timer = new Timer(100,10);
soundFadeInTimer.addEventListener("timer", soundFadeIn);
soundFadeInTimer.start();
_mute = false;
}
private static function soundFadeIn(e:TimerEvent)
{
fadeOutIncr += 1/10;
sAmbienceVol = new SoundTransform(fadeOutIncr, 0);
channel.soundTransform = sAmbienceVol;
}
}
}