MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 768

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

You can write a conditional statement that returns a Boolean value in two ways. The second
example is preferable:
if (cartArr.length>0) {
return true;
} else {
return false;
}
Compare this example with the previous one:
// better
return (cartArr.length > 0);
The second snippet is shorter and has fewer expressions to evaluate. It's easier to read and to
understand.
The following example checks if the variable
of
or a value of zero (0).
x/y
return ((y > 0) ? x/y : 0);
The following example shows another way to write this code. This example is preferable:
if (y>0) {
return x/y;
} else {
return 0;
}
The shortened
statement syntax from the first example is known as the conditional
if
operator (
). It lets you convert simple
?:
case, the shortened syntax reduces readability.
If you must use conditional operators, place the leading condition (before the question mark
[
]) inside parentheses to improve the readability of your code. You can see an example of this
?
in the previous code snippet.
Writing compound statements
Compound statements contain a list of statements within braces (
these braces are indented from the compound statement. The following ActionScript code
shows an example of this:
if (a == b) {
// This code is indented.
trace("a == b");
}
768
Best Practices and Coding Conventions for ActionScript 2.0
is greater than zero (0), and returns the result
y
statements into a single line of code. In this
if..else
). The statements within
{}

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

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?

This manual is also suitable for:

Flash 8

Table of Contents