Monday, January 14, 2013

Parentheses

Parentheses (()) can be used in three ways in ActionScript 3.0. First, parentheses can be used to change the order of operations in an expression. Operations that are grouped inside parentheses are always executed first. For example, parentheses are used to alter the order of operations in the following code:
trace (2 + 3 * 4); // output: 14
trace ( (2 + 3) * 4); // output: 20
Second, parentheses can be used with the comma operator (,) to evaluate a series of expressions and return the result of the final expression, as shown in the following example.
var a:int = 2;
var b:int = 3;
trace((a++, b++, a+b)); // output: 7
Third, parentheses can be used to pass one or more parameters to functions or methods, as shown in the following example, which passes a string value to the trace function.
trace("hello"); // output: hello
Programming Actionscript 3. Powered by Blogger.