| |
In my previous tutorial, you have seen a short ActionScript and what is ActionScript. Now it is the time to closely look into the atomic elements of ActionScript programs. Like any other scripting language ActionScript is a collection of whitespace, comments, identifiers, Actions or statements, keywords, operators and separators. We will look into each of these elements in this tutorial.
Like any other scripting language, ActionScript has some syntax rules that needs to be followed. If we are not following these syntaxes ActionScript will not compile and run.
Before reading further we need to understand an important character of ActionScript. Like most of the other scripting language ActionScript is a case sensitive scripting language. That means 'hello', 'Hello' and 'HELLO' are not same for ActionScript.
Whitespace
In ActionScript you do not need to follow any special indentation rules. For example, the Example ActionScript that we have written in our previous tutorial could have been written all on one line or in any other strange way you felt like typing it, as long as there was at least one whitespace character between each token that was not already delineated by an operator or separator. In ActionScript, a whitespace is a tab space, or newline.
Identifiers
Identifiers are used for identifying class names, method names, and variable names. An identifier may be any sequence of uppercase or lowercase letters, numbers, or the underscore or dollar-sign characters. An identifies must start with a letter or underscore (_) or dollar sign($). Again, ActionScript is case-sensitive, so "NAME" is a different identifier than "name" or "Name". Some examples of valid identifiers are:
Hello World count a4 $name this_is_ok
Invalid variable names include:
2count high-temp Not/ok
Literals
A constant value in ActionScript is created by using a literal representation of it. For example, here are some literals:
100 98.6 ‘X’ “This is a test”
Left to right, the first literal specifies an integer, the next is a floating-point value, the third is a character constant, and the last is a string. A literal can be used anywhere a value of its type is allowed.
Comments
ActionScript supports three type of Comments. single-line and multiline.
Single line comments, comments a single line. Single line comments uses a two forward slashes (//) to comment. For example :
//This is a comment
Multi line comments are useful if you want to comment a block of statements. Multiline comments start with /* and ends with */. For example
/*
This is a multiline comment.
Everything inside this comments will be ignored.
*/
Comments can be of any length. Comments do not need to follow rules for ActionScript syntax or keywords. var age:Number = 20;
Separators In ActionScript, there are some characters that act as separators. The most commonly used separator in ActionScript is the semicolon (;). A semicolon in ActionScript is used to terminate the statements. The separators are shown in the following table:
| Symbol |
Name |
Purpose |
| ( ) |
Parentheses |
Used to contain lists of parameters in method definition and invocation. Also used for defining precedence in expressions, containing expressions in control statements. |
| { } |
Braces |
Used to define a block of code, for classes, methods, and local scopes. |
| [ ] |
Brackets |
Used to declare array types. Also used when dereferencing array values. |
| ; |
Semicolon |
Terminates statements. |
| , |
Comma |
Separates consecutive identifiers in a variable declaration. Also used to chain statements together inside a for statement. |
| . |
Period |
It is used to separate properties or methods from an object. |
ActionScript keywords
Keywords are special words that is having a special meaning to the compiler. There are 32 reserved keywords currently defined for ActionScript. For the complete list of ActionScript keywords see the table below.
These keywords, combined with the syntax of the operators and separators, creates an ActionScript. We cannot use these keywords as the name of an Identifier.
| break |
case |
class |
continue |
default |
delete |
| dynamic |
else |
extends |
for |
function |
get |
| if |
implements |
import |
in |
instanceof |
interface |
| intrinsic |
new |
private |
public |
return |
set |
| static |
switch |
this |
typeof |
var |
void |
| while |
with |
|
|
|
|
In addition to these keywords ActionScript also reserves 'true', 'false', 'null' and 'undefined'. These are values defined by ActionScript. You may not use these words as and identifier.
|
|