home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
404 Jogos
/
CLJG.iso
/
Esportes
/
CrossingCup.swf
/
scripts
/
__Packages
/
SoundManager.as
< prev
next >
Wrap
Text File
|
2007-12-11
|
10KB
|
359 lines
class SoundManager
{
function SoundManager(_mcRoot)
{
this.mcRoot = _root;
}
function addSpeaker()
{
var _loc3_ = {_x:772.1,_y:1.5};
this.mcSpeaker = this.mcRoot.attachMovie("speaker","speaker",1000,_loc3_);
this.mcSpeaker.show();
this.mcSpeaker.gotoAndStop(1);
this.mcSpeaker.onMouseDown = function()
{
if(this.hitTest(_root._xmouse,_root._ymouse))
{
this.toggleSound();
}
};
this.mcSpeaker.toggleSound = function()
{
if(this._currentframe == 1)
{
this.gotoAndStop(2);
SoundManager.ins().MusicMute();
}
else
{
SoundManager.ins().MusicOn();
this.gotoAndStop(1);
}
};
}
function loadSounds()
{
this.mcRoot.createEmptyMovieClip("mcSoundAll",10000);
this.mcRoot.mcSoundAll.createEmptyMovieClip("mcSound",10000);
this.mcRoot.mcSoundAll.createEmptyMovieClip("mcSound2",10001);
this.mcRoot.mcSoundAll.createEmptyMovieClip("mcSound3",10002);
this.mcRoot.mcSoundAll.createEmptyMovieClip("mcSound4",10003);
this.bgm = new Sound(this.mcRoot.mcSoundAll.mcSound);
this.bgm.attachSound("bgm");
this.ambience = new Sound(this.mcRoot.mcSoundAll.mcSound2);
this.ambience.attachSound("ambience");
this.ambience2 = new Sound(this.mcRoot.mcSoundAll.mcSound2);
this.ambience2.attachSound("oi");
this.goal = new Sound(this.mcRoot.mcSoundAll.mcSound3);
this.goal.attachSound("goal");
this.whistle = new Sound(this.mcRoot.mcSoundAll.mcSound.group4);
this.whistle.attachSound("wistleshort");
this.kick = new Sound(this.mcRoot.mcSoundAll.mcSound.group4);
this.kick.attachSound("kick");
this.an1 = new Sound(this.mcRoot.mcSoundAll.mcSound.group4);
this.an1.attachSound("an1");
this.an2 = new Sound(this.mcRoot.mcSoundAll.mcSound.group4);
this.an2.attachSound("an4");
this.an3 = new Sound(this.mcRoot.mcSoundAll.mcSound.group4);
this.an3.attachSound("an3");
this.an4 = new Sound(this.mcRoot.mcSoundAll.mcSound.group4);
this.an4.attachSound("an4");
this.mouseover = new Sound(this.mcRoot.mcSoundAll.mcSound.group4);
this.mouseover.attachSound("mouseover");
this.mousedown = new Sound(this.mcRoot.mcSoundAll.mcSound.group4);
this.mousedown.attachSound("mousedown");
this.heartput = new Sound(this.mcRoot.mcSoundAll.mcSound.group4);
this.heartput.attachSound("heartput");
this.goalplayed = false;
}
function setOverallVolume()
{
this.bgm.setVolume(CSessionManager.ins().sndMusicVolume);
this.ambience.setVolume(CSessionManager.ins().sndEffectsVolume);
this.ambience2.setVolume(CSessionManager.ins().sndEffectsVolume);
this.goal.setVolume(CSessionManager.ins().sndEffectsVolume);
this.whistle.setVolume(CSessionManager.ins().sndEffectsVolume);
this.kick.setVolume(CSessionManager.ins().sndEffectsVolume);
this.mouseover.setVolume(CSessionManager.ins().sndEffectsVolume);
this.mousedown.setVolume(CSessionManager.ins().sndEffectsVolume);
this.heartput.setVolume(CSessionManager.ins().sndEffectsVolume);
}
function setMusicVolume()
{
this.bgm.setVolume(CSessionManager.ins().sndMusicVolume);
}
function setEffectVolume()
{
this.ambience.setVolume(CSessionManager.ins().sndEffectsVolume);
this.ambience2.setVolume(CSessionManager.ins().sndEffectsVolume);
this.goal.setVolume(CSessionManager.ins().sndEffectsVolume);
this.whistle.setVolume(CSessionManager.ins().sndEffectsVolume);
this.kick.setVolume(CSessionManager.ins().sndEffectsVolume);
this.mouseover.setVolume(CSessionManager.ins().sndEffectsVolume);
this.mousedown.setVolume(CSessionManager.ins().sndEffectsVolume);
this.heartput.setVolume(CSessionManager.ins().sndEffectsVolume);
}
function playBGM()
{
this.bgm.setVolume(CSessionManager.ins().sndMusicVolume);
this.bgm.onSoundComplete = mx.utils.Delegate.create(this,this.completeBGM);
this.bgm.stop();
this.bgm.start(0);
this.loopbgm = true;
}
function completeBGM()
{
if(this.loopbgm)
{
this.bgm.start(0);
}
}
function stopBGM()
{
this.bgm.stop();
this.loopbgm = false;
}
function fadeBGM(fadein)
{
if(fadein)
{
this.playBGM();
this.bgm.setVolume(0);
this.ibgm = setInterval(this,"fadinginbgm",100);
}
else
{
this.ibgm = setInterval(this,"fadingoutbgm",100);
}
}
function fadinginbgm()
{
var _loc2_ = this.bgm.getVolume();
_loc2_ += 5;
this.bgm.setVolume(_loc2_);
if(_loc2_ >= CSessionManager.ins().sndMusicVolume)
{
_loc2_ = CSessionManager.ins().sndMusicVolume;
clearInterval(this.ibgm);
}
}
function fadingoutbgm()
{
var _loc2_ = this.bgm.getVolume();
_loc2_ -= 5;
this.bgm.setVolume(_loc2_);
if(_loc2_ <= 0)
{
_loc2_ = 0;
clearInterval(this.ibgm);
this.bgm.stop();
}
}
function playWhistle()
{
this.whistle.start();
this.whistle.onSoundComplete = this.completeWhistle;
}
function completeWhistle()
{
_global.__DISPATCH({type:"endwhistle"});
}
function stopWhistle()
{
this.whistle.stop();
}
function playKick()
{
this.kick.start();
}
function stopKick()
{
this.kick.stop();
}
function playMouseover()
{
this.mouseover.start();
}
function stopMouseover()
{
this.mouseover.stop();
}
function playMousedown()
{
this.mousedown.start();
}
function stopMousedown()
{
this.mousedown.stop();
}
function playHeartput()
{
this.heartput.start();
}
function stopHeartput()
{
this.heartput.stop();
}
function playAmbience2()
{
this.ambience2.start(0,2);
}
function stopAmbience2()
{
this.ambience2.stop();
}
function playVictory()
{
switch(this.randRange(1,4))
{
case 1:
this.an1.start();
break;
case 2:
this.an2.start();
break;
case 3:
this.an3.start();
break;
case 4:
this.an4.start();
}
}
function stopVictory()
{
this.an1.stop();
this.an2.stop();
this.an3.stop();
this.an4.stop();
}
function fadinginambience2()
{
if(Math.random() < 0.3)
{
this.ambience2.start(0,1);
}
}
function fadeAmbience(fadein)
{
if(fadein)
{
this.ambience.start(0,1000);
this.ambience.setVolume(0);
this.iambience = setInterval(this,"fadinginambience",100);
this.iambience2 = setInterval(this,"fadinginambience2",3000);
}
else
{
this.iambience = setInterval(this,"fadingoutambience",100);
}
}
function fadinginambience()
{
var _loc2_ = this.ambience.getVolume();
_loc2_ += 5;
this.ambience.setVolume(_loc2_);
if(_loc2_ >= CSessionManager.ins().sndEffectsVolume)
{
_loc2_ = CSessionManager.ins().sndEffectsVolume;
clearInterval(this.iambience);
}
}
function fadingoutambience()
{
var _loc2_ = this.ambience.getVolume();
_loc2_ -= 5;
this.ambience.setVolume(_loc2_);
if(_loc2_ <= 0)
{
_loc2_ = 0;
clearInterval(this.iambience);
clearInterval(this.iambience2);
this.ambience.stop();
}
}
function playGoal()
{
this.goalplayed = true;
this.goal.start();
this.goal.setVolume(CSessionManager.ins().sndEffectsVolume);
}
function stopGoal()
{
this.goalplayed = false;
this.goal.stop("goal");
}
function fadeGoal(fadein)
{
if(fadein)
{
this.goalplayed = true;
this.goal.start(0);
this.goal.setVolume(0);
}
else
{
if(this.goal.getVolume() == 0)
{
return undefined;
}
this.igoal = setInterval(this,"fadingoutgoal",100);
}
}
function fadingingoal()
{
var _loc2_ = this.goal.getVolume();
_loc2_ += 5;
this.goal.setVolume(_loc2_);
if(_loc2_ >= 80)
{
_loc2_ = 80;
clearInterval(this.igoal);
}
}
function fadingoutgoal()
{
var _loc2_ = this.goal.getVolume();
_loc2_ -= 10;
this.goal.setVolume(_loc2_);
if(_loc2_ <= 0)
{
_loc2_ = 0;
clearInterval(this.igoal);
this.igoal = undefined;
this.goal.setVolume(0);
this.goal.stop("goal");
this.goalplayed = false;
}
}
function MusicMute()
{
this.lastVolM = CSessionManager.ins().sndMusicVolume;
this.lastVolE = CSessionManager.ins().sndEffectsVolume;
CSessionManager.ins().sndMusicVolume = 0;
CSessionManager.ins().sndEffectsVolume = 0;
this.setMusicVolume();
this.setEffectVolume();
}
function MusicOn()
{
CSessionManager.ins().sndMusicVolume = this.lastVolM;
CSessionManager.ins().sndEffectsVolume = this.lastVolE;
this.setMusicVolume();
this.setEffectVolume();
}
function randRange(min, max)
{
var _loc1_ = Math.floor(Math.random() * (max - min + 1)) + min;
return _loc1_;
}
static function _buildInstance()
{
SoundManager._oI = new SoundManager();
return SoundManager._oI;
}
static function ins()
{
return !(SoundManager._oI instanceof SoundManager) ? SoundManager._buildInstance() : SoundManager._oI;
}
}