MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 178

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

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
the result into the variable
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
exercise) as
myScore++
way of saying
myScore = myScore + 1
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 doesn't have assignment operators. It relies on the
increment operator instead.
178
Syntax and Language Fundamentals
.
myScore
or even
myScore += 1
, because it handles an increment and assignment
and the number 1, and then stores
myScore
myScore = myScore + 1
. The increment operator (
(from the previous
) is a simplified
++

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash 8

Table of Contents