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/Bookmark
Leave a Reply


TxEff - The Flash Text Effects