In Macromedia Flash 5, the assignment operator (=) and the equality operator (==) appear to be similar but are used for completely different reasons.

The assignment operator (=) is used to assign a value to a variable, element of an array, or property of an object. Here are a few examples of using the assignment operator:

// Set a variable to a value. var userName = "Jack"; // Set an element of an array to a value. namesArray[3] = "Jack"; // Set a property of a object to a value. nameClip._visible = FALSE;

The equality operator (==) is used to compare two values or expressions. It is used to compare numbers, strings, Boolean values, variables, objects, arrays, or functions. The result is TRUE if the expressions are equal and FALSE otherwise. How items are compared depends on their data type:

  • Numbers, strings, and Boolean values are compared byvalue, and are considered equal if they have the same value. For instance, two strings are equal if they have the same number of characters.
  • Variables, objects, arrays, and functions are compared byreference. Two variables are equal if they refer to the same object, array, or function. Two separate arrays are never considered equal, even if they have the same number of elements.

For example, in the following expression, the value ofuserName and the string "Jack" are the same and expression evaluates to TRUE:

(userName == "Jack"); // TRUE. // However... (userName == "jack"); // FALSE.

The second expression evaluates to FALSE because "Jack" is not the same string value as "jack".

However, when comparing two variables, array, objects, or functions, an equality expression will evaluate to TRUE only if the items being compared point to the same reference. For example, consider the following:

var userName = "Jack"; var user = "Jack";

Although the two variables contain the same value the variables themselves are not equal, since they point to different references. For example:

(userName == user); // FALSE // However... (eval(userName) == eval(user)); // TRUE

The second expression is TRUE because the two variables were first evaluated (using the eval function) and their values, rather than their references, are being compared.

A practical example of using the equality operator

The equality operator is often used in the following manner to check if a movie has completely loaded:

if (_framesloaded == _totalframes) {  gotoAndPlay (3); } else {  gotoAndPlay (1); }

Additional Information

For more details on preloading a movie please refer to How to create movies that download before playing (TechNote12588).

Keywords: tn_14982

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy