# ActionScript Programming/PartI/Chapter 2

## Operators (1)[edit | edit source]

In this chapter you will learn all of the operators which are used in ActionScript.

**Usual operators**

Operator | Description |
---|---|

" " | Text. Example: "hello", "hi", "button" |

() | performs a grouping operation on one or more parameters, or surrounds one or more parameters and passes them as parameters to a function outside the parentheses. Example: trace ("hello!!!"); |

**Arithmetic operators**

Operator | Description |
---|---|

- |
used for negating or subtracting. Example: a = 5 – 2; b = a -1; |

% | calculates the remainder of expression1 divided by expression2. Example trace (12% 5); returns 2 |

* | multiplies two numerical expressions. Example: a = 5 * 5; b = a * 2; |

/ | divides expression1 by expression2. Example: a = 20 / 4; b = a / 5; |

+ |
adds numeric expressions or concatenates (combines) strings. Example: a = 5 + 5; b = "hel" + "lo"; |

**Assignment operators**

Operator | Description |
---|---|

-= |
assigns expression1 the value of expression1 -expression2. a = 5; b = 2; a -= b instead of a = a - b; |

%= |
assigns expression1 the value of expression1% expression2. a = 12; b = 5; a%=b instead of a=a % b; |

*= | assigns expression1 the value of expression1 *expression2. a = 2; b = 4; a *= b instead of a = a * b; |

/= |
assigns expression1 the value of expression1/expression2. a = 4; b = 2; a /= b instead of a = a / b; |

+= |
assigns expression1 the value of expression1 + expression2. a = 3; b = 2; a += b instead of a=a + b; |

= |
assigns the type of expression2 to expression1. b = "hello"; z = b; c = z + "!!!"; |

Other operators are discussed later after chapter Data types.

### Comments[edit | edit source]

Comments are useful for keeping track of what you intended, and for passing information to other developers if you work in a collaborative environment or are providing samples. There are two types of using comments. The first one is a one line comment and the other one: multi-line comment. For implementing one line comment just put "//" followed by your comment at the end of the line, if the line is not empty, and at the beginning of the line if it is empty. Examples:

This example demonstrates the use of comment at the end of the line

```
box._rotation = 45; //This rotates "box" object by 45 degrees
```

This example demonstrates the use of comment in an empty line

```
//This is just a comment
```

This example demonstrates the use of comment in an empty line in work

```
//Rotating "box" object by 45 degrees
box._rotation = 45;
```

Note that you cannot use any type of comment inside the script! For implementing a multi-line comment you must just put your comment between symbols "/*" and "*/" (Note that all rules applied for one line comment are also applied for multi-line comment). Examples:

```
/* We are now going to
rotate our box by 45
degrees */
box._rotation = 45;
box._rotation = 45; /* Rotating our box by 45 degrees */
/* Rotating our box by 45 degrees */
box._rotation = 45;
// Box has been rotated!
```

You cannot use comments like this:

```
box._rotation = 4/*just comment*/5;
```

This is a syntax error.