# ActionScript Basics: One

Data Types

* Strings or Literal Values [“ActionScript”]
* Numbers [5]
* Boolean [true] – these are useful for making decisions

Variables

A variable is a container that is used to store your data
variable = value;
How to Write Variables
Naming Variables: Important Tips to Remember

* Don’t Use Reserved Names such as: {}, ;, (), break, call, case, continue, default,delete,do,else, function,for,if,in,new,on,return,set,switch,this,typeof,var,void,while, and with.
* Don’t Use Spaces
* Don’t Begin Variables with Numbers
* Don’t User Operators in Variable Names
* Don’t Use the period (.) operator in your variable names

Example Variable Names

* cow
* cowPuke

Three Ways of Writing Variables

* nQuantity = 10;
* var nQuantity = 10;
* nQuantity:Number = 10;

var nQuantity:Number <-- how you declare the datatype and variable nQuantity = 5; - an expression which says nQuantity is equal to 5. Assignment Operators * (addition) * - (subtraction) * = (assignment) [for assigning variables] * == (equality) [test two expressions for equaltiy nQuantity == 10] * / (division) [divides two expressions 10/20] * * (multiplication) [multiples two expressions 10 * 20] * (increment) [add 1 to an expression, nQuantity ] * -- (decrement) [subtract 1 from an expression, nQuantity--] * < (less than) [compares two expressions] * > (greater than) [compares two expressions]
* != (inequality) [test for inequality of two expressions – nQuantity != 10;]
* = (addition assignment) [example experession1 = is the value of expression1 expression2, shorter way to write this out]
* -= (subtraction assignment) [examples expression1-= is really saying subtract expression 1 from expression 2]

Expressions

Expressions are often sequences of literals and variables linked together by mathematical symbols. We can generate values to be stored in variables by writing expressions.
How to Write Expressions

The Example below highlights how you can use variables along with operators to store new values.
var nQuantity, nResult;
nQuantity = 20;
nResult = nQuantity – 10;
Using trace to debug your actionscript

You can use the trace command to debug your actionscript and see the results of your expressions in the output window.
var nQuantity, nResult;
nQuantity = 20;
nResult = nQuantity – 10;
trace(nResult);
Input and Output

Using Dynamic Text Files in Flash you can pass variables to and from flash by entering the variable name into the Var field in the properties window.

This site uses Akismet to reduce spam. Learn how your comment data is processed.