Flash variables tutorial Difficulty: Beginner
A variable is a data holder, it can be used to store and retrieve useful information within your flash movie. For example you could store the number of sections in your site in a variable nbSections by using the actionscript code below.
nbSections = 7;
You could also store your first name into a variable firstName by using the actionscript code below:
firstName = "Frank";
You can store many types of data in a variable. By assigning a value to a variable, you automatically set its type to the type of the value. In other words, if you assign a numerical value to the variable, the data type of the variable will be set to number.
Variable types
String Variables
String variables are variables containing characters (letters, digits). For example, the variable my_name could hold the value "John Doe" which is a chain of characters. Note that the " " quotes are mandatory to specify the value is a string
Example of a variable with a string value
my_name = "John Doe ";
Number Variables
A number variable holds a numerical value which can be manipulated using operators and functions. Note that no " " quotes are required in this case because the value is not a chain of characters but a number.
Examples of variables with numerical values
number1 = 556;
number2 = 0.99;
Boolean Variables
A boolean variable is a very small variable containing two possible values: true or false. For example, you could use a boolean variable to store the login state of a user as shown in the code below.
Example of variables with boolean values
// user is logged
user_logged = true;
// user is not logged
user_logged = false;
That should start you off with creating and setting variables with actionscript.
Next Flash Tutorial >Working with variables Part 1 |