ActionScript 3 fundamentals: Syntax

The syntax of a programming language is the set of rules you must follow when writing code. Syntax error are some of the most common errors made by developers, especially when they are first leaning a language. Typically, the compiler connot compile code that contains syntax errors. One thing to keep in mind - syntax does not provide information on the meaning behind the symbols or structure in your code.

In this article, you will learn the syntax of Actionscript 3.0 :

Case Sensitivity


Actionscript 3.0 is a case-sensitive language. Identifiers that differ only in case are considered different indetifiers.

var exampleVariable:int;
var ExampleVariable:int;

 

Semicolons

The semicolon character ( ; ) is used to terminate a statment. If you omit the semicolo, the compiler assumes that each line of code represents a single statament. Terminating each statement with a semicolon is good practice and makes your code easier to read.

Parentheses

You can use parentheses ( ( ) ) in three ways in Actionscript 3. First, you can use parentheses to change the order of operations in an expression. Operations thar are grouped inside parentheses are always executed first. For example, parentheses are used to alter the older of operations in.

trace (2 + 3 * 4); // result is 14

trace ( (2 + 3) * 4); // result is 20

or :
You can use parantheses with the comma operator.

var a : int = 2 ;
var b : int = 3 ;
trace ((a++, b++, a+b)) // and result is 7

or : 

You can use parentheses to pass one or more parameters ro functions or methods.

trace ("hello world");

Code Block

One or more line of code enclosed in curly brackets ( { } ) is calld a block. Code is grouped together and organized into block in Actionscript 3.0. For Examples :

function exampleFunction():void {
   var exmpVar : String = "hello world"
   trace(exmpVar);
}

for (var i:uint = 10; i>0; i--){
     trace (i);
}

Whitespace

Any spacing in code - spaces, tabs, line breaks, and so on-is referred to as whitspace.The compiler ignore extra whitespace that is used to make code easier to read. For example :

for (var i:uint = 0; i<10; i++){
     trace(i);
}
for(var i:uint = 0; i<10, i++){trace(i);}

Source : www.adobe.com

Share this

Related Posts

Previous
Next Post »