Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / ActionScript Technology Center / Learning ActionScript 3 /

ActionScript 3 fundamentals: Syntax

by Michelle Yaiser

Michelle Yaiser
  • Adobe
  • michelleyaiser.com

Content

  • Case sensitivity
  • Semicolons
  • Parentheses
  • Code blocks
  • Whitespace
  • Comments
  • Literals
  • Keywords and reserved words
  • Slash syntax
  • Where to go from here
  • Acknowledgement

Created

24 October 2011

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
ActionScript Adobe AIR Flash Builder Flash Player Flash Professional

Requirements

User level

Beginning

Required products

  • Flash Builder (Download trial)
  • Flash Professional (Download trial)

The syntax of a programming language is the set of rules you must follow when writing code. These rules dictate the symbols and words that can be used and how to structure your code. Syntax errors are some of the most common errors made by developers, especially when they are first learning a language. Typically, the compiler cannot 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. The semantics of a programming language provide the meaning behind the symbols, keywords, and structure. A program that is syntactically correct may not be semantically correct.

In this article, you will learn the syntax of ActionScript 3.

Case sensitivity

ActionScript 3 is a case-sensitive language. Identifiers that differ only in case are considered different identifiers. For example, the following code creates two different variables:

var sampleVariable:int; var SampleVariable:int;

Semicolons

The semicolon character ( ; ) is used to terminate a statement. If you omit the semicolon, the compiler assumes that each line of code represents a single statement. 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 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); // 14 trace((2 + 3) * 4); // 20

Second, you can use parentheses with the comma operator ( , ) to evaluate a series of expressions and return the result of the final expression. This technique is shown in the following example:

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

Third, you can use parentheses to pass one or more parameters to functions or methods. In the following example, a String value is passed to the trace() function:

trace("hello"); // hello

Code blocks

One or more lines of code enclosed in curly brackets ( { } ) is called a block. Code is grouped together and organized into blocks in ActionScript 3. The bodies of most programming constructs like classes, functions, and loops are contained inside blocks.

function sampleFunction():void{ var sampleVariable:String = "Hello, world."; trace(sampleVariable); } 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 whitespace. The compiler ignores extra whitespace that is used to make code easier to read. For example, the following two examples are equivalent:

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

Comments

As you write ActionScript, you can leave notes to yourself or others. For example, use comments to explain how certain lines of code work or why you made a particular choice. Code comments are a tool you can use to write text that the computer ignores in your code. ActionScript 3 code supports two types of comments: single-line comments and multiline comments. The compiler ignores text that is marked as a comment.

Single-line comments begin with two forward slash characters ( // ) and continue until the end of the line. For example, the following code contains a single-line comment:

// a single line comment

Multiline or block comments begin with a forward slash and asterisk ( /* ) and end with an asterisk and forward slash ( */ ).

/* This is multiline comment that can span more than one line of code. */

Another common use of comments is to temporarily "turn off" one or more lines of code. For example, use comments to figure out why certain ActionScript code isn't working the way you expect by placing the code within comment syntax so that the compiler ignores it. You can also use comments to test a different way of doing something.

Literals

A literal is any fixed value that appears directly in your code. The following examples are literals:

17 "hello" -3 9.4 null undefined true false

Literals can also be grouped to form compound literals. The following example shows a compound literal being passed as a parameter to the Array class constructor.

var myStrings:Array = new Array(["alpha", "beta", "gamma"]); var myNumbers:Array = new Array([1,2,3,5,8]);

Keywords and reserved words

Reserved words are words that you cannot use as identifiers in your code because the words are reserved for use by ActionScript. Reserved words include lexical keywords, which are removed from the program namespace by the compiler. The compiler reports an error if you use a lexical keyword as an identifier. The following table lists ActionScript 3 lexical keywords.

Table 1. ActionScript 3 Lexical Keywords

as

if

return

break

implements

super

case

import

switch

catch

in

this

class

instanceof

throw

const

interface

to

default

internal

true

delete

is

try

do

native

typeof

else

new

use

extends

null

var

false

package

void

finally

private

while

for

protected

with

function

public

 

There is a small set of keywords, called syntactic keywords, that can be used as identifiers, but that have special meaning in certain contexts. The following table lists ActionScript 3 syntactic keywords.

Table 2. ActionScript 3 Syntactic Keywords

each

include

override

get

dynamic

static

set

final

 

namespace

native

 

There are also several identifiers that are sometimes referred to as future reserved words. These identifiers are not currently reserved in ActionScript 3. However, Adobe recommends avoiding these words because a subsequent version of the language may include them as keywords.

Table 3. ActionScript 3 Future Reserved Words

abstract

export

throws

boolean

float

to

byte

goto

transient

cast

intrinsic

type

char

long

virtual

debugger

prototype

volatile

double

short

 

enum

synchronized

 

Slash syntax

Slash syntax is not supported in ActionScript 3. Slash syntax was used in earlier versions of ActionScript to indicate the path of a movieclip or variable.

Where to go from here

Now that you are familiar with the syntax, learn other fundamentals of programming in ActionScript 3. Begin with ActionScript 3 fundamentals: Variables, ActionScript 3 fundamentals: Data types, ActionScript 3 fundamentals: Operators, and ActionScript 3 fundamentals: functions.

Acknowledgement

The content in this article is based on material originally published in the Learning ActionScript 3 user guide created by Adobe Community Help and Learning.

More Like This

  • ActionScript 3 fundamentals: Data types
  • ActionScript 3 fundamentals: Numbers and Math
  • ActionScript 3 fundamentals: Variables
  • ActionScript 3 fundamentals: Associative arrays, maps, and dictionaries
  • AS3 fundamentals: Conditionals
  • ActionScript 3 fundamentals: Arrays
  • Garbage collection internals for Flash Player and Adobe AIR
  • ActionScript 3 fundamentals: Functions
  • ActionScript 3 fundamentals: Packages
  • ActionScript 3 fundamentals: Operators

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement