1. Computing

Getting to Know Flash CS5: What Are ActionScript 3.0 Variables?

By

Getting to Know Flash CS5: What Are ActionScript 3.0 Variables?
Getting to Know Flash CS5: What Are ActionScript 3.0 Variables?
To understand ActionScript 3.0, first you need to understand the basic building blocks of scripting. One of the most important building blocks is the variable. Variables represent values used in scripts; variables can be fixed numbers or strings of characters, or they can change based on various factors.

You can define a variable simply by using the command var followed by the variable name and a semicolon; this instructs Flash to establish a variable of a specific name. In the image above, I create a variable called myvariable, then define it as a particular type (integer). On the next line, I make myvariable equal to the number 42.

Another example of a variable might be a user's name. If you create a Flash script that collects the user's name and then displays it later, you might assign a variable called username to the input field where the user types in their name. The value of username would change every time a new name is typed in. You can also assign variables to things like frame numbers, object / symbol sizes, and numerous other things - all of which might change during the course of the Flash movie, thus changing the value of the variable.

You can think of variables in a fashion similar to the classic x in algebra, which is usually most people's first encounter with the concept of variables. You probably groaned the first time you saw x = y + 1, but the concept is the same when applied to variables in ActionScripting. The variable x is defined to have a specific value, which can be constant or can change depending on the value of another variable, y.

©2014 About.com. All rights reserved.