Archive for the ‘Coding’ Category

I couldnt believe the Math.round() function in AS3 is so crippled. All it returns is the nearest integer value and ofcourse there is no way you can specify what is the precision of rounding. To make it worse it always rounds 1.5 to 1. Hmmm..

But the solution to this problem is pretty simple.  For example if u want a 2 decimal place rounding all we have to do is multply with 100,then round it and then divide it by 100. Confusing..well here is the code:

public static function roundDecimal(num:Number, precision:int):Number{

var decimal:Number = Math.pow(10, precision);

return Math.round(decimal* num) / decimal;


Well that was pretty simple right. Now go coding..all the best.

Unlike C and java where u can declare an m x n array simply by writing arr[m][n], its a bit difficult in actionscrpit3.
It was like u have to make an array of arrays:

new Array(new Array(),new Array(),…)

But a little bit effort can find a way out of this mess. You may make use of the following snippet:

function arrayTest(){

var m:int = 2;
var n:int = 2;
var mainArr:Array = new Array(m);
var i:int;
var j:int;
for (i = 0; i < m; i++) {

mainArr[i] = new Array(n);
for (j = 0; j < n; j++) {

mainArr[i][j] = “[” + i + “][” + j + “]”;




It is a bit of a mess but it will work for sure..

Sometimes you need to pass more than one arguements other than the “event” object. In that case you can use the following code:

//–Listener Function–//

private function listenerFunction(e:MouseEvent,passedVariable:Object): void {


private function callerFunction(): void {
      var callerObject:Object = {name:"I have a name for sure..."};

            someObject.addEventListener(MouseEvent.CLICK,function (e:MouseEvent) : void {

Hope that was useful.

Well some time back when I was coding some C for modifying  Linux kernel my guide said ,”Make sure you dont use floating points”.It was that suggestion that aroused my curiousity about floating points and thus I stumbled upon this article.

What Every Computer Scientist Should Know About Floating-Point Arithmetic…




This one explains floating point arithmatic very clearly. I think every computer scientist should know about floating point arithmetic before he wants to code something serious. Thats why I thought of sharing this one with you.