Static variables and methods

Well, my reading of “Essential Actionscript 3.0” continues. Lets see whether we are going “Static” or not.

Static and Instance variable of the same name can co-exist in a class. In order to access the static variable, one must write the class name before the variable name ( myClass.PROPERTY ).Only the variable name by itself will refer to the instance variable. Therefore, Instance variable is said to “shadow” the Static variable.
By convention, Static variables are declared before Instance variables in a class.

Static methods can not use “this” key word.
Static methods can not access “Instance” variables and methods.

Actionscript automatically creates one Static method, known as “class initializer” for every class. Code in the class initializer runs in interprited mode, and is not compiled by JIT compiler. Because JIT compiled code generally executes much more quickly than interpreted  code, one should move all the processor-intencive code out of the class initializer when performance is a priority.

Every class in Actionscript is represented at runtime by an instance of the “Class” class.

Advertisements

Author: saumya

designer / developer / maker / educator @saumya

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s