Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Design > Adobe Creative Suite

  • Print
  • + Share This
This chapter is from the book

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.

  1. 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);
  2. 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.
  • + Share This
  • 🔖 Save To Your Account