Archive for the “Code snippets” Category

Recently I was asked if I know how to show a number with a fixed number of digits after the decimal point. Here is how it can be done:

var num:Number = 12.3456;
trace(num.toFixed(2));// => 12.34

ATTENTION: This method toFixed returns String. If you want to have a Number after using this method you should use casting or:

var num:Number = 12.3456;
var num2:Number = Number(num.toFixed(2));
// => returns Number not String
  • Share/Bookmark

Comments No Comments »

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: Read the rest of this entry »

  • Share/Bookmark

Comments No Comments »

TxEff - The Flash Text Effects