EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 178

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
178 Syntax and Language Fundamentals
To manipulate values using operators:
1. Create a new Flash document.
2. Open the Actions panel (Window > Actions) and type the following code into the
Script pane:
// example one
var myScore:Number = 0;
myScore = myScore + 1;
trace("Example one: " + myScore); // 1
// example two
var secondScore:Number = 1;
secondScore += 3;
trace("Example two: " + secondScore); // 4
3.
Select Control > Test Movie.
The Output panel displays the following text:
Example one: 1
Example two: 4
The addition operator is fairly straightforward, because it adds two values together. In the
first code example, it adds the current value of
myScore and the number 1, and then stores
the result into the variable
myScore.
The second code example uses the addition assignment operator to add and assign a new
value in a single step. You can rewrite the line
myScore = myScore + 1 (from the previous
exercise) as
myScore++ or even myScore += 1. The increment operator (++) is a simplified
way of saying
myScore = myScore + 1, because it handles an increment and assignment
simultaneously. You can see an example of the increment operator in the following
ActionScript:
var myNum:Number = 0;
myNum++;
trace(myNum); // 1
myNum++;
trace(myNum); // 2
Notice that the previous code snippet doesnt have assignment operators. It relies on the
increment operator instead.

Table of Contents

Related product manuals