Appendix B. ActionScript Operators Reference

ActionScript Operators Reference

The following is a list of the operators in ActionScript 3.0:

Basic Operators

The following table shows the operators used throughout the language in a variety of situations.

Operator

Description

Example

=

Assignment; assigns the value on the right to the expression on the left

var name:String = "Mal";

.

Accesses properties or methods of objects or separates class names from package names

mcBox1.scaleX = 42;

()

Groups mathematical operators or invokes functions and methods

this.gotoAndPlay(42);

:

Declares data type

var lastName:String;

+

Concatenates strings

var fullName:String = firstName + " " + lastName;

Mathematical Operators

The following table describes the operators used in mathematical expressions:

Operator

Description

Example

+

Performs addition

var total:Number = num1 + num2;

-

Performs subtraction

var total:Number = num1 – num2;

*

Performs multiplication

var total:Number = num1 * num2;

/

Performs division

var total:Number = num1 / num2;

%

Returns modulus, the remainder in a division problem

var total:Number = num1 % num2;

++

Increments the value by one

i++;

--

Decrements the value by one

i--;

+=

Adds the value to the right to the current value of the variable

newTotal += num1; //same as newTotal = newTotal + num1;

-=

Subtracts the value to the right from the current value of the variable

newTotal -= num1; //same as newTotal = newTotal – num1;

*=

Multiplies the value to the right by the current value

newTotal *= num1; // same as newTotal = newTotal * num1;

/=

Divides the value to the right by the current value

newTotal /= num1; // same as newTotal = newTotal / num1;

Comparison Operators

The following table summarizes the comparison operators that you can use in your scripts:

Operator

Description

Example

<

Less than

var isTrue:Boolean = num1 < num2;

>

Greater than

var isTrue:Boolean = num2 > num1;

<=

Less than or equal to

var isTrue:Boolean = num3 <= num4;

>=

Greater than or equal to

var isTrue:Boolean = num4 >= num3;

!=

Not equal to

var isTrue:Boolean = num5 != num6;

==

Equal to

var isTrue:Boolean = num7 == num8;

Boolean Operators

The following table summarizes the Boolean operators available in ActionScript 3.0:

Operator

Description

Example

!

Logical NOT; negates value

if(!num1.isBoolean())

||

Logical OR

if(num1 > num2 || num3 < num4)

&&

Logical AND

if(num5 <= num6 && num7 >= num8)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.107.255