about
history
syntax
visu
arcade
goodies
wrappers
efficiency
examples
experiments
tabageos
tutorials
actiontad logo white
ActionScript Programming Efficency and Best Practices
 

A key to good programming is getting the most out of
the smallest/most efficient amount of code.

The ActionScript language contains many tools and techniques that help minimize
the amount of code needed in a project.

As you get deeper into programming with ActionScript 3.0,
efficiency is one of the things you will need to be mindful of.

The other concept that is good to master is Object Oriented Programming.
I like to think of it as sort of creating your own little language.
You use Classes and sets of Classes, Interfaces and Namespaces
to signalize and organize common behaviors and functions.

One overall good idea from oop is that each class should only worry about itself
and/or the immediate classes it controls.
In AS3, in general, when you need communication between classes, dispatch events.

Performance Tips
 
  • Try to minimize new calls. (like - new Sprite())
    As much as possible limit new calls to constructor functions.
  • Limit the creation/use of Strings in loops.
    If in a situation where you feel strings are a must, consider events.
  • Limit the use of function calls in looping functions.
    var largest:Number = a>b?a:b;   is faster than   var largest:Number = Math.max(a,b);
  • Use int instead of Number whenever possible.
  • Events and Arrays are very useful.


To Upper Case or not
 

camelCase is the term for the industry standard technique of Capatalizing the start of new words in a variable:
(for example:  myText   mouseDownHandler)
Using camelCase helps in phrase recognition.
But it can also get confusing keeping up with what is supposed to be capatalized,
especially when the programming language is using camelCase as well.

For my own personal applications I tend to give things with more importance camelCase,
and the lesser variables of my own, that are mostly local variables, lowercase.

without camelCase:
package
{

 import flash.display.Sprite;

 public class myclass extends Sprite
 {

   public function myclass()
   {

     var myvar:Sprite = new Sprite();
     addChild(myvar);

   }

 }

}
with camelCase:

package
{

 import flash.display.Sprite;

 public class myClass extends Sprite
 {

   public function myClass()
   {

     var myVar:Sprite = new Sprite();
     addChild(myVar);

   }

 }

}


These kind of details are really just a matter of opinion.
However, most people prefer camelCase simply because it is the standard.

back to top









actiontad twitter.com/actiontad terms