The web site for Flash ActionScript 3.0 game developers

 
         
   

Ask Gary: AS3 Capitalization

Gary,

Is there a rule for knowing when a built in function, property, etc
will start with a capital, be all caps, or start lower case? For example,
addEventListener starts lower case, MouseEvent start upper case, and
ROLL_OVER is all caps. I am coming out of ASP programming and just
keeping my variables the right case and remembering all the new commands
is hard enough - but having to remember which commands are which case is a
bit much. Let me know if there is a good rule to remember these by.

Thanks.
Brandon

Good question. This is especially important when you consider that AS3 is case sensitive. So addEventListener is a function, but AddEventListener is nothing.
It seems the convention is that functions start with lowercase, then capitalize each word after that. Like gotoAndStop. Classes start with capital letters, like the Math in Math.random(). Constants use all caps and underlines between words, like ENTER_FRAME.
But I wouldn't take that for granted. And it doesn't really matter too much because the auto-completion in the AS3 programming windows will list the command for you as you type.
What I would avoid though is using capitalization to differentiate between functions or functions and variables. For instance, I wouldn't use moveObject as a function and then moveobject as a variable. It works, but I wouldn't do it.
I do kinda break that rule sometimes when I have a movie clip that by its nature will only be on the stage once. For instance, the space ship in an asteroids game. I might call that SpaceShip in the library and as a class, and then spaceShip will be the instance name. It makes it easier for me to find the movie clip in the Library based on the instance name I'm using in the code.



Copyright Gary Rosenzweig