- Changing a Property Value
- Changing Position
- Increasing or Decreasing a Property's Value
Increasing or Decreasing a Property's Value
Rather than setting a property to a specific value, you can add to or subtract from its current value. For example, rather than rotating the star in the previous example by 90 degrees, you could write code that would take the current amount of rotation and add to or subtract from it.
The following steps create some code that adds five degrees to the star's rotation every time it's clicked:
- Select and delete all the code that was typed in the Actions panel in the previous procedure, replacing it with the following code:
star_mc.addEventListener(MouseEvent.CLICK, rotateStar); function rotateStar(e:MouseEvent):void{ star_mc.rotation+=5; }
- Now test the movie. Each time the star is clicked, it should rotate an additional five degrees.
Using += in the code is a shorthand way of saying "Take the current value of the object on the left and add the value on the right to it." Here's the longhand way to do the same thing:
star_mc.rotation = star_mc.rotation + 5;