Jun 15
Static initializations in ActionScript, Take 2
In a previous post I discussed how you can use the [Mixin] metadata tag to create a static initialization in Flex. Here is another way to do pretty much the same thing:
public dynamic class Model { trace('I get called first'); public function Model() { } }
The trace statement and any other code that is directly inside the class body will be invoked when the class is loaded. You can read more about this here.

June 15th, 2007 at 2:46 pm
I realize this may be semantics, but is it really considered a function closure? Isn’t it simply a code block?
Curious, what is the scope of the code within? Is it scoped statically to the class? If you defined a variable within, is it local to the block? (I assume yes)
Btw, in FF your comments in the code are chopped a little. In IE the Archives and Tags sections get moved below the reply area, but in FF those sections don’t move and the overflow runs under them.
June 15th, 2007 at 3:43 pm
you don’t even need the {}
public dynamic class Model
{
trace(’I get called first’);
public function Model() {}
}
in fact any statement get executed whatever the order
public dynamic class Model
{
trace(’I get called first’);
public function Model() {}
trace(’I get called too’);
}
June 15th, 2007 at 4:44 pm
@Derek – Agreed about the semantics, though I am going to change the post based on zwetan’s comment to remove the block. The scope issue will make much more sense once th block is gone.
@zwetan – Thanks. I updated the post to reflect this.
June 19th, 2007 at 2:06 am
[...] In the Model class above you will see two calls to Mixin.extendClass(). The extendClass method takes the class in the second argument and mixes its methods and properties (both static and instance) in to the class in the first argument. These methods calls are directly inside the class block, so they are invoked when the Model class object is initialized. You can read more about this in my previous post about static initializations in ActionScript. [...]
February 1st, 2008 at 9:12 am
[...] http://flexonrails.net/?p=78 http://flexonrails.net/?p=66 [...]