Variable auto-conversion rules
Action Script automatically converts a base variable to the appropriate type. The following list illustrates the variable auto-conversion rules from a basic variable type to the other types.
An empty variable is a string that can be equated to the “” value. Strings that consist of only white space characters are also considered empty.
For auto-conversion, long variables are treated as integers.
Converting string variables
- To Boolean: any non-empty value converts to true. Empty strings convert to false.
- To float: a numeric string is converted to its float value. If the string is non-numeric, an exception is caused.
- To integer: a numeric string is converted to its integer value. If the string is non-numeric, an exception is caused.
Converting Boolean variables
- To string: string representation: true becomes
“true”; false becomes “false”
- To float: true becomes 1.0; false
becomes 0.0
- To integer: true becomes 1; false
becomes 0
Converting float variables:
- To string:
string representation: 3.142 becomes “3.142”
- To Boolean: any non-zero value is true; zero converts to false
- To integer: the non-fractional value of the float is used to define the integer value. For example, 3.564 becomes 3
Converting integer variables:
- To string:
string representation: 3142 becomes “3142”
- To Boolean: any non-zero value is true. Zero
converts to false.
- To float:
direct conversion to a float value (multiplies integer value by 1.0). For example, 1 becomes 1.0.
The only time auto-conversion can fail is when a string cannot be converted to a numeric equivalent. Auto-conversion rules apply to expression evaluation and to a variable’s values being used as parameters in object methods or object variable methods.