Expressions
Expressions are formulas that combine variables with other variables and numbers, text, or operators, and evaluate them all to a single value. To better understand expressions, let’s use another example:
var total:Number = 12 * 2;
To the right of the equal sign is the expression 12*.2. When this script is executed, the expressions 12*.2 will be replaced by the result of 12 multiplied by 2, or 24.
An expression can also contain variables like the following script:
var total:Number = myCount * taxpercent;
Expression can also contain numbers, functions (which I will cover next), or anything else that will return a value when evaluated.
Expressions are used to peform the following scripting tasks and much more:
- Set variable values
- Determine whether conditions are being met
- Dynamically name movie clips
- Call functions dynamically
Expressions enable you to avoid hard-coding values that will remain the same no matter what else happens during the playback of the Flash movie. By using expressions to assign and manipulate values, you can make your Flash project more dynamic, which in turn results in more interactive projects. Many of the more intermediate and advanced scripts you will start to work with as your scripting skills grow will rely heavily on expressions. Without them, your projects cannot be dynamic, which means they will play back exactly the same way every time they are viewed.