AS3: Setting Values to Instance Variables in their Declaration

AS3 allows you to set the value to an instance variable in its declaration. This can be a value of any type, a string, an int, an object, even another instantiated class. If an instance variable will definitely be used in every instance, it makes to set it's value in the declaration - as opposed to setting it in the constructor. This makes no difference in memory usage or performance, but it makes things a little easier to read - and saves you from that extra line of code.

In other words, you can do this:
package{  
     public class Foo{
          private var sayHello:SayHello = new SayHello("Hello World");

          public function Foo(){

          }
     }
}
Instead of doing this:
package{  
     public class Foo{
          private var sayHello:SayHello;

          public function Foo(){
               sayHello = new SayHello("Hello World");
          }
     }
}

A word of caution: I have found there is one case where you have to be careful with this type of syntax. And that is when you embed fonts in a textField. You need to make sure you unembed them before you set your instance eligible for garbage collection. Otherwise certain browsers will crash when the instance is destroyed.

Therefore, before you set your instance to be eligible for garbage collection, set all the textFields that use embedded fonts to false.

To recap, make sure you call a method like clean() before you set your instance of Foo to be eligible for garbage collection:
package{  
     import flash.text.TextField;
     import flash.text.TextFormat;

     public class Foo{
          private var tf:TextField = new TextField();

          public function Foo(textStr:String){
               tf.text = textStr;
               tf.embedFonts = true;
               tf.setTextFormat(new TextFormat("FunkyFont", 23));
          }
          public function clean():void{ // call before setting elligible for gc
               tf.embedFont = false;
          }
     }
}
The class instantiating Foo
package{  
     import flash.display.Sprite;

     public class Bar extends Sprite{
          private var foo:Foo = new Foo("Hello World");

          public function Bar(){
               addChild(foo);

               removeChild(foo);
               foo.clean();
               foo = null;
          }
     }
}