Flash CS3 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript language elements > Operators > != inequality operator | |||
expression1 != expression2
Tests for the exact opposite of the equality ( ==) operator. If expression1 is equal to expression2 , the result is false. As with the equality (==) operator, the definition of equal depends on the data types being compared, as illustrated in the following list:
Comparison by value means what most people would expect equals to mean--that two expressions have the same value. For example, the expression (2 + 3) is equal to the expression (1 + 4) when compared by value.
Comparison by reference means that two expressions are equal only if they both refer to the same object, array, or function. Values inside the object, array, or function are not compared.
When comparing by value, if expression1 and expression2are different data types, ActionScript will attempt to convert the data type of expression2 to match that of expression1.
Availability: ActionScript 1.0; Flash Player 5
expression1 : Object - A number, string, Boolean value, variable, object, array, or function.
expression2 : Object - A number, string, Boolean value, variable, object, array, or function.
Boolean - The Boolean result of the comparison.
The following example illustrates the result of the inequality (!=) operator:
trace(5 != 8); // returns true trace(5 != 5) //returns false
The following example illustrates the use of the inequality (!=) operator in an if statement:
var a:String = "David";
var b:String = "Fool";
if (a != b) {
trace("David is not a fool");
}
The following example illustrates comparison by reference with two functions:
var a:Function = function() { trace("foo"); };
var b:Function = function() { trace("foo"); };
a(); // foo
b(); // foo
trace(a != b); // true
a = b;
a(); // foo
b(); // foo
trace(a != b); // false
// trace statement output: foo foo true foo foo false
The following example illustrates comparison by reference with two arrays:
var a:Array = [ 1, 2, 3 ]; var b:Array = [ 1, 2, 3 ]; trace(a); // 1, 2, 3 trace(b); // 1, 2, 3 trace(a!=b); // true a = b; trace(a); // 1, 2, 3 trace(b); // 1, 2, 3 trace(a != b); // false // trace statement output: 1,2,3 1,2,3 true 1,2,3 1,2,3 false
! logical NOT operator, !== strict inequality operator, && logical AND operator, || logical OR operator, == equality operator, === strict equality operator
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00001280.html