in black and white
Main menu
Share a book About us Home
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics

macromedia flash mx - Reinhardt R.

Reinhardt R., Lott J macromedia flash mx - John Wiley & Sons, 2004. - 987 p.
ISBN 0-7645-4354-7
Download (direct link): macromediaflash2004.pdf
Previous << 1 .. 56 57 58 59 60 61 < 62 > 63 64 65 66 67 68 .. 419 >> Next

>>>= Right shift zero fill by value x >>>— y X — x >>> y
&= Bitwise AND by value x &— y X — x & y
| = Bitwise OR by value x | — y X —x | y
A — Bitwise XOR by value x a— y X — x > y
As we mentioned, there is really only one fundamental operator in the assignment operator category — the equal sign. Each of the additional operators merely saves you some time typing. For example, the following expression
nQuantity += 6;
is the shorthand version of this operator:
nQuantity = nQuantity + 6;
Either of the two preceding expressions means that you want Flash to add 6 to the current value of nQuantity. It just so happens that the former variation is shorter and quicker to type.
Chapter 5 ¦ Constructing ActionScript
The operators compounded with the equals (=) operator are either mathematical operators or bitwise operators (covered in the following sections of this chapter). So if you have any questions about how the compound operators work, simply consult the appropriate section in which the basic operators are discussed. In each case, the compound operator follows the same pattern. For example:
nQuantity *= 6;
is the same as:
nQuantity = nQuantity * 6;
Working with Comparison Operators
Comparison operators allow you to compare operands. The result of a comparison is a Boolean value: true or false. These operators are most often used in expressions called conditionals within if...else blocks, and control of flow expressions within for and while blocks. (You learn about these types of statements later in this chapter.) But the basic premise is that if the conditional expression evaluates to true, then a block of code is executed, and if it evaluates to false, the block of code is skipped over.
Using comparison operators (see Table 5-4), you can compare strings, numbers, and Boolean values. These primitive datatypes are equal only if they contain the same value. You can also compare reference data types such as objects, functions, and arrays. But reference data types are equal only if they reference the same object, whether or not they contain the same value.
Table 5-4: Comparison Operators
Operator Name
== Equals
j = Not equals
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
=== Strict equality
!== Strict inequality
Perhaps the most common mistake made in programming is confusing the equality equals operator (==) with the assignment equals operator (=). In fact, even among seasoned professionals, it is not uncommon to make this error on occasion. The difference is so tiny in print, but the result is so drastic. Take, for instance, the following example:
var nQuantity:Number = 999;
if (nQuantity = 4){
trace("if condition true");
104 Part II ¦ Laying the ActionScript Foundation
What would you expect this code to do? Even if you don’t know what some of the code structures mean, you can probably figure out that after nQuantity is assigned a value of 999, you want the code to check to see if nQuantity i s equal to 4. If that condition is true, it should write a message to the Output panel. Finally, it writes the value of nQuantity to the Output panel.
You might expect that the final value of nQuantity i s still 999. But because the wrong operator was mistakenly used in the if condition (nQuantity = 4), nQuantity has been assigned the value of 4! Can you see the problems that have been caused by one missing character?
So the corrected code looks more like this:
var nQuantity:Number = 999; if (nQuantity == 4){
trace("if condition true");
Any datatype can be compared using the equality operators. String characters are first converted to the ASCII values and then compared, character by character. Therefore, “a” is less than “z” and lowercase letters have higher values than their uppercase counterparts. Tables 5-5 and 5-6 show examples of numbers and strings being compared, using the equality operators along with the resulting value of the expression.
Table 5-5: Number Comparison
Expression Result
6 == 6 true
6 != 6 false
6 > 6 false
6 < 6 false
6 >= 6 true
6 <= 6 true
Table 5-6: String Comparison
Expression Result
"Joey"== "Joey" True
"joey" != "Joey" True
"joey" > " Joey" True
"Joey" < " 'Joseph" false
Chapter 5 ¦ Constructing ActionScript 105
The only two operators in this category that you have not yet looked at are the strict equality (===) and strict inequality (!==) operators. These operators work much like the non-strict counterparts (== and !=) with one difference: They don’t perform datatype conversions automatically. What this means is that when using the regular equality equals operator (==),
Flash automatically converts the operands to the same datatype before testing for equality. Therefore, the values 5 and "5" are equal when testing using the regular equality operator (==) but not when using the strict equality operator (===). Table 5-7 gives some examples of the difference between using regular and strict equality operators.
Previous << 1 .. 56 57 58 59 60 61 < 62 > 63 64 65 66 67 68 .. 419 >> Next