Naming conventions in ActionScript

 

Here I will explain which naming convention I use when programming in ActionScript 3.0. This will hopefully make it easier to follow along in my examples and guides in other articles.

General rules

Names made up of more than one word is written together without spaces or underscores using camel case. Camel case means that each word starts with a capital letter and the following letters are in lower case. The first letter of the first word is in lower case except for class names.

manyWordsTogether
ClassName

Variables

I always begin private variable names with a _.

private var _test:Number;

I rarely use variables that are protected, public or internal. Instead I use getters and setters with the wanted scope to get and set a private variable.

private var _test:Number;
public function get test():Number
{
   return _test;
}
public function set test(v:Number):void
{
   _test = v;
}

I always start the names of local variables with a t

public function test2():void
{
   var tTest:Number = 2;
}

The only exception from local variables starting with t is for loop variables. I commonly use i and j as variables in loops.

public function test3():void
{
   for (var i:uint = 0; i < 3; i++)
   {
   }
}

Functions and methods name

I always start names of functions and methods with a lower case letter and use camel case to indicate each new word in the name.

Function parameters

I start the name of parameters with an r.

public function test4(rValue:Number):void
{
}

I have a couple of exceptions from this rule and that is for setters where I use the parameter name v and for event listeners where I use e as the parameter name.

public function set test(v:Number):void
{
   _test = v;
}

public function test5(e:Event):void
{
}