originalp
02-07-2011, 03:48 PM
Hello :D,
I'm trying to control sounds in my Flash with as3. I'm new to as3. Please help!
CLASS
I'm using a class with just a global boolean variable to trigger all sounds on or off:
package {
public class videosglobal {
public static var soundoff:Boolean;
}
}
Sound on/off buttons
import videosglobal
soundoff_btn.addEventListener(MouseEvent.CLICK,cli ccato);
//Note: "cliccato" is the name of the function, only here it appears with a space I don't know why, nevermind that.
function cliccato(m:MouseEvent):void
{
//SoundMixer.stopAll();
soundoff_btn.alpha=0;
soundon_btn.alpha=1;
//nevermind the alpha, it's just to make one or the other button visible.
videosglobal.soundoff=true;
//BOOLEAN GLOBAL VARIABLE IN CLASS SHOULD BE TRUE NOW.
}
soundon_btn.addEventListener(MouseEvent.CLICK,clic ccato2);
//Note: "cliccato2" is the name of the function, only here it appears with a space I don't know why, nevermind that.
function cliccato2(m:MouseEvent):void
{
//stopAllSounds Behavior
soundoff_btn.alpha=1;
soundon_btn.alpha=0;
//nevermind the alpha, it's just to make one or the other button visible.
videosglobal.soundoff=false;
//BOOLEAN GLOBAL VARIABLE IN CLASS SHOULD BE FALSE NOW.
}
MOVIE CLIPS
Now, I have different movieclips with sounds on their own timeline so I thought I could just ask for the global variable on the first frame of every sound in my Flash to mute all sounds if the sound on/off buttons are pressed (that's the whole idea!) :
import videosglobal
n=new Sound();
n.attachSound("airplane_sound");
if (videosglobal.soundoff==true){
n.stop();
}
else {
n.start(0, 1);
}
;
ERRORS
"Access of undefined property n."
But I don't even know if I'm doing the global boolean variable in a class right!
Please help!!
:confused:
I'm trying to control sounds in my Flash with as3. I'm new to as3. Please help!
CLASS
I'm using a class with just a global boolean variable to trigger all sounds on or off:
package {
public class videosglobal {
public static var soundoff:Boolean;
}
}
Sound on/off buttons
import videosglobal
soundoff_btn.addEventListener(MouseEvent.CLICK,cli ccato);
//Note: "cliccato" is the name of the function, only here it appears with a space I don't know why, nevermind that.
function cliccato(m:MouseEvent):void
{
//SoundMixer.stopAll();
soundoff_btn.alpha=0;
soundon_btn.alpha=1;
//nevermind the alpha, it's just to make one or the other button visible.
videosglobal.soundoff=true;
//BOOLEAN GLOBAL VARIABLE IN CLASS SHOULD BE TRUE NOW.
}
soundon_btn.addEventListener(MouseEvent.CLICK,clic ccato2);
//Note: "cliccato2" is the name of the function, only here it appears with a space I don't know why, nevermind that.
function cliccato2(m:MouseEvent):void
{
//stopAllSounds Behavior
soundoff_btn.alpha=1;
soundon_btn.alpha=0;
//nevermind the alpha, it's just to make one or the other button visible.
videosglobal.soundoff=false;
//BOOLEAN GLOBAL VARIABLE IN CLASS SHOULD BE FALSE NOW.
}
MOVIE CLIPS
Now, I have different movieclips with sounds on their own timeline so I thought I could just ask for the global variable on the first frame of every sound in my Flash to mute all sounds if the sound on/off buttons are pressed (that's the whole idea!) :
import videosglobal
n=new Sound();
n.attachSound("airplane_sound");
if (videosglobal.soundoff==true){
n.stop();
}
else {
n.start(0, 1);
}
;
ERRORS
"Access of undefined property n."
But I don't even know if I'm doing the global boolean variable in a class right!
Please help!!
:confused: