Variables are an important aspect of coding in actionscript. In fact, they are essentially what makes a game. Variables are used to store data. They can store numbers, words, or whether something is true or false. In this article I’m going to be going over each type of variable in AS2 and their use.

1. Boolean

Booleans are used to test whether a variable is true or false. The data stored in them either reads true or false. They are useful for when you want something to happen only after something is determined to be true. Here is an example:

if(light==true){//if the variable light is true...
light.gotoAndStop('on');//turn the light on.
}//end

2. String

A string is a variable that stores words or letters. It can be used for passwords or codes in a game. Here is an example of a string.

if(password=='abc');//if the password is abc.
gotoAndStop('win');//stop on the win frame.
}//end

2. Number

Numbers are incredibly useful variables. A number, obviously, is used to store a number. Numbers can be used to keep score, track time, count lives, and for so much more. Here is an example of numbers in use:

if(time==0);//if the time is 0...
gotoAndStop('end');//stop on the end frame
}//end

Related posts:

  1. Code Bits: Trace
  2. Code Bits: if statements
  3. Code Bits: Timeline