|
ActionScript Reference Operators
-= (subtraction assignment)
-= (subtraction assignment)
Entry Owner: Scott Manning, Started: September 24, 2003
The subtraction assignment operator is an easier and cleaner way to subract one expression from another. It only works with numbers or expressions that have numeric values.
Example 1: Using variables
s = 20;
t = 15;
s -= t;
trace(s);
The code above assigns a value of 20 to s and 15 to t. It then assigns the value of s minus t to s. The result is 5.
Variables must always have numeric values to be used with this operator. The following code will return NaN because m does not have a numeric value.
p = 10;
m = "Hello";
p -= m;
trace(p);
Example 2: Using numbers
x = 10;
x -= 5;
trace(x);
You don't always have to subract an expression from another expression. You can subract numbers from expressions as well. The code above returns a value of 5.
|