While blog stumbling this morning, I have discovered that AS3 allows static initializers (or sometimes called static constructors). This allows a chunk of code to execute when the class is first referenced in a static fashion (for example while grabbing a static property). Below is a quick example of the syntax needed:

package {
  public class Test {
     {trace("Static Initializer");}
  }
}

I can’t think of anything particularly useful for this method except for very unique cases where frameworks or singletons need immediate initialization functionality sometime before their instance constructor is run…

Blog stumbles:
New ActionScript 3 Singleton Method
43 Hot Flex and ActionScript 3.0 APIs, tips and tools for Autumn 2008


Author: Jonathan Dunlap
Jonathan is an experienced software engineer, sole blogger of JADBOX, author of FlashMVC, humanitarian, and has contracted work for Microsoft, Coke, and Disney.
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • email
  • Furl
  • LinkedIn
  • Pownce
  • Reddit
  • StumbleUpon
  • TwitThis
Auto-Generated Related Posts:
  1. FlashMVC 2.0 Released!...
  2. Countdown to Mobile Flash Player 10...
  3. Detroit Design Patterns Lecture pt. 2...

Tags: