Instantiate (declare) a VAR using the general AS3 syntax form:
va <instance name of var>:<type of var> = new <type of var>();
In this case, "instance name of var" is a name you assign for the variable and "type of var" is the class name of the type of variable object you want to create a variable for.
Use the following var statement:
var A:Number = new Number();
to instantiate a number variable named A which can be used to store decimal numbers.
Assign the number variable A a decimal value of 5.99 and print the results to the AS3 output panel with the code
A = 5.99;
trace (A);
Declare another number variable, called B. Store the decimal number 0.01 in it and add it the value of variable A, 5.99, then display the result in the Output panel, 6.00 with the code
var B:Number = new Number();
B = 0.01;
trace (A+B);
Use the var statement
var B:String= new String();
B = "this is text stored in string variable named B"
to instantiate a string variable named B which is used to store text in quotes above. Always surround text with double quotes when assigning text to a string variable.
Use the var statement
var myButton:MovieClip = new MovieClip();
to instantiate a movie clip variable named myButton which is used to store movie clips and build new movie clips. Add a red rectangle graphic to the myButton MovieClip variable with graphic methods and properties of the MovieClip class with the code
myButton.graphics.lineStyle(4);
myButton.graphics.beginFill(0xFF0000);
myButton.graphics.drawRect(100, 50, 50, 20);
myButton.graphics.endFill();
Place myButton movie clip variable object on the stage with the AS3 addChild method code
addChild(myButton);
Use the var statement
var textdisplay:TextField = new TextField(");
to instantiate a TextField variable named textdisplay. Assign text to be stored in the textdisplay variable with the TextField "text" property as in
textDisplay.text = "this is the text in the textDisplay TextField";
Always include double quotation marks around the text to be stored in the text property of a TextField object.