jserete
11-19-2011, 02:20 PM
Help!
I need help with a problem:
* I try to call a function which calls a sound for my game when a player hits an object
* I set an if statement to try and stop it once it plays
* I'm not sure if that's working
Anyway,
Here's the code
var sfxNum = 0;
onEnterFrame = function ()
{
if (_root.a1.s == true or _root.a2.s == true or _root.a3.s == true or _root.a4.s == true or _root.a5.s == true or _root.a6.s == true or _root.a7.s == true)
{
playSoundOnce();
}
if (dead == false)
{
firstMusic == 0 ? (mm0.start(), firstMusic = 1) : null;
MUSIC ? mm0.setVolume(40) : mm0.setVolume(0);
count++;
}
};
SFX = true;
sss_loopSound;
MUSIC = true;
firstMusic = 0;
this.createEmptyMovieClip("m0",100);
mm0 = new Sound(m0);
mm0.attachSound("bg0");
mm0.onSoundComplete = function()
{
mm0.start();
};
function playSound(id:String, vol:Number, loopVersion:Boolean)
{
if (SFX)
{
if (!loopVersion)
{
this.createEmptyMovieClip("sss" + soundNum,10500 + soundNum);
var __reg2 = new Sound(this["sss" + soundNum]);
__reg2.attachSound(id);
__reg2.setVolume(vol);
__reg2.start();
soundNum >= 30 ? (soundNum = 0) : soundNum++;
}
else
{
if (!sss_loopVersion)
{
this.createEmptyMovieClip("sss_loopVersion",10531);
sss_loopSound = new Sound(this["sss_loopVersion"]);
sss_loopSound.attachSound(id);
sss_loopSound.setVolume(vol);
sss_loopSound.start();
}
sss_loopSound.onSoundComplete = function()
{
sss_loopSound.start();
};
}
}
}
function playSoundOnce()
{
if(sfxNum<1){
trace("sfxNum<1 and sfxNum = "+sfxNum);
playSound("3",70,false);
sfxNum++;
trace("now sfxNum = "+sfxNum);
}
}
I need help with a problem:
* I try to call a function which calls a sound for my game when a player hits an object
* I set an if statement to try and stop it once it plays
* I'm not sure if that's working
Anyway,
Here's the code
var sfxNum = 0;
onEnterFrame = function ()
{
if (_root.a1.s == true or _root.a2.s == true or _root.a3.s == true or _root.a4.s == true or _root.a5.s == true or _root.a6.s == true or _root.a7.s == true)
{
playSoundOnce();
}
if (dead == false)
{
firstMusic == 0 ? (mm0.start(), firstMusic = 1) : null;
MUSIC ? mm0.setVolume(40) : mm0.setVolume(0);
count++;
}
};
SFX = true;
sss_loopSound;
MUSIC = true;
firstMusic = 0;
this.createEmptyMovieClip("m0",100);
mm0 = new Sound(m0);
mm0.attachSound("bg0");
mm0.onSoundComplete = function()
{
mm0.start();
};
function playSound(id:String, vol:Number, loopVersion:Boolean)
{
if (SFX)
{
if (!loopVersion)
{
this.createEmptyMovieClip("sss" + soundNum,10500 + soundNum);
var __reg2 = new Sound(this["sss" + soundNum]);
__reg2.attachSound(id);
__reg2.setVolume(vol);
__reg2.start();
soundNum >= 30 ? (soundNum = 0) : soundNum++;
}
else
{
if (!sss_loopVersion)
{
this.createEmptyMovieClip("sss_loopVersion",10531);
sss_loopSound = new Sound(this["sss_loopVersion"]);
sss_loopSound.attachSound(id);
sss_loopSound.setVolume(vol);
sss_loopSound.start();
}
sss_loopSound.onSoundComplete = function()
{
sss_loopSound.start();
};
}
}
}
function playSoundOnce()
{
if(sfxNum<1){
trace("sfxNum<1 and sfxNum = "+sfxNum);
playSound("3",70,false);
sfxNum++;
trace("now sfxNum = "+sfxNum);
}
}