Using relational and equality operators
Relational and equality operators, also called comparison operators, compare values of
expressions, and they return either
comparison operators in conditional statements and loops to specify the condition for when
the loop should stop.
You can use the equality (
operands are equal, and this comparison returns a Boolean value. String, number, or Boolean
operand values compare using a value. Object and array operands are compared by a
reference.
In this example, you can see how to use the equality operator to test the array's length and
display a message in the Output panel if there are no items in the array.
var myArr:Array = new Array();
if (myArr.length == 0) {
trace("the array is empty.");
}
When you select Control > Test Movie, the string
Output panel.
You can use the equality operator to compare values, but you cannot use the equality operator
to set values. You might try to use the assignment operator (=) to check for equality.
To use relational and equality operators in your code:
1.
Create a new Flash document.
2.
Type the following ActionScript into Frame 1 of the Timeline:
var myNum:Number = 2;
if (myNum == 2) {
// do something
trace("It equals 2");
}
In this ActionScript, you use the equality operator (
whether the variable
3.
Select Control > Test Movie.
The string
It equals 2
4.
Return to the authoring environment and change:
var myNum:Number = 2;
to:
var myNum:Number = 4;
190
Syntax and Language Fundamentals
or
true
false
) operator to figure out whether the values or references of two
==
equals 2.
myNum
appears in the Output panel.
(a Boolean value). You frequently use
the array is empty
) to check for equality. You check
==
appears in the
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?