Increment and Decrement Operators
When you work with ActionScript a lot, you'll commonly be adding or removing 1 from variables and properties.
To make this process easier, there is a shortcut called the increment and decrement operators. Take a look at the following code.
- Create a new ActionScript 3.0 project and enter in the following code for the project:
// Increment and Decrement var myValue:Number = 5; trace(myValue); myValue++; trace(myValue); myValue--; trace(myValue);
- Run this project. You'll see the following in the Output panel:
5 6 5
In the increment and decrement example, the value of myValue is initially set at 5 and is sent to the Output panel. The number is then increased by 1 and sent again, resulting in 6.When you add a double minus, --, to the end, it decrements the value by 1. The value of myValue is already 6 based on the previous function, and is then decremented to be 5 again.