Lesson 7
static
Those of you who are familiar with AS2 know what is a static member of a class.
Static variables are part of the class where they are declared and can only be called through the class as shown below. If we create an instance of the class and call the static variable through the instance we will get an error when we compile the script. Static variables are very useful, because since they belong to the class they will be available at every point.
package
{
import flash.display.Sprite;
import flash.text.TextField;
public class Starter_9 extends Sprite
{
private var tField:TextField;
public function Starter_9 ()
{
myTest();
}
private function myTest():void
{
var a:Testvar = new Testvar ();
tField = new TextField();
tField.text = Testvar.test;
addChild(tField);
}
}
}
//
import flash.display.Sprite;
class Testvar extends Sprite
{
public static var test:String;
public function Testvar()
{
test = "I am static";
}
}