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 = m 1;
trace("Example one: " + myScore); // 1
// example two
var secondScore:Number = 1;
secon= 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 = m 1
(from the previous
exercise) as
+
or even
m= 1
. The increment operator (
++
) is a simplified
way of saying
myScore = m 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 doesn’t have assignment operators. It relies on the
increment operator instead.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...