List of some useful ActionScript code snippets:

How to toggle button with two states in two lines of code,i.e. sound on/off button?

Let’s say you have a movieclip called “sound_btn” with two frames for the two states – sound on and sound off. Here is the code:

sound_btn.onRelease = function(){
 
this.gotoAndStop(Number(soundIsOn)+1);
 
soundIsOn = !soundIsOn;
 
}

The code soundIsOn = !soundIsOn; is equal to:

if(soundIsOn){
 
soundIsOn = false;
 
}else{
 
soundIsOn = true;
 
}

And the line this.gotoAndStop(Number(soundIsOn)+1); sends the movie clip to a frame number depending on the value of the Boolean variable soundIsOn. Number(soundIsOn) = 1 if soundIsOn = true, and Number(soundIsOn) = 0 if soundIsOn = false.

Share
Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

*


TxEff - The Flash Text Effects