Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • SiteCatalyst
  • Students
  • Elements family

Adobe Creative Cloud

  • What is Adobe Creative Cloud?
  • Design
  • Web
  • Photography
  • Video
  • Students
  • Teams
  • Enterprise
  • Educational institutions

Design and photography

  • Photoshop
  • Illustrator
  • InDesign
  • Adobe Muse
  • Lightroom

Video

  • Adobe Premiere
  • After Effects

Web development and HTML5

  • Edge Tools & Services [opens in a new window]
  • Dreamweaver
  • Gaming [opens in a new window]

Adobe Marketing Cloud

  • What is Adobe Marketing Cloud?
  • Digital analytics
  • Social marketing
  • Web experience management
  • Testing and targeting
  • Media optimization

Analytics

  • SiteCatalyst
  • Adobe Discover
  • Insight

Social

  • Adobe Social

Experience Manager

  • CQ
  • Scene7

Target

  • Test&Target
  • Recommendations
  • Search&Promote

Media Optimizer

  • AdLens
  • AudienceManager
  • AudienceResearch

Document services

  • Acrobat
  • EchoSign [opens in a new window]
  • FormsCentral [opens in a new window]
  • SendNow [opens in a new window]
  • Acrobat.com [opens in a new window]

Publishing

  • Digital Publishing Suite

  • See all products
Business solutions

By business need

  • Digital analytics
  • Digital publishing
  • Document management
  • Media optimization
  • Social marketing
  • Testing and targeting
  • Video editing and serving
  • Web development [opens in a new window]
  • Web experience management
  • See all business needs

By industry

  • Broadcast
  • Education
  • Financial services
  • Government
  • Publishing
  • Retail
  • See all industries
Support & Learning

I need help

  • Products
  • Adobe Creative Cloud
  • Adobe Marketing Cloud
  • Forums [opens in a new window]

I want to learn

  • Training and tutorials
  • Certification [opens in a new window]
  • Adobe Developer Connection
  • Adobe Design Center
  • Adobe TV [opens in a new window]
  • Adobe Marketing Center
  • Adobe Labs [opens in a new window]
Download
  • Product trials
  • Adobe Flash Player
  • Adobe Reader
  • Adobe AIR
  • See all downloads
Company
  • Careers at Adobe
  • Investor Relations
  • Newsroom
  • Privacy
  • Corporate Social Responsibility
  • Customer Showcase
  • Contact us
  • More company info
Buy
  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers
  • Adobe Marketing Cloud sales [opens in a new window]
Search
 
Info Sign in
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Welcome,
My Adobe
My orders
My information
My preferences
My products and services
Sign out
My cart
Privacy My Adobe
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out Privacy 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
Promotions
Estimated shipping
Tax
Calculated at checkout
Total
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
ActionScriptAdobe AIRFlash BuilderFlash PlayerFlash Professional
Was this helpful?
Yes   No

By clicking Submit, you accept the Adobe Terms of Use.

 
Thanks for your feedback.

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: Operators
  • ActionScript 3 fundamentals: Packages
  • ActionScript 3 fundamentals: Arrays
  • ActionScript 3 fundamentals: Loops
  • ActionScript 3 fundamentals: Variables
  • ActionScript 3 fundamentals: Data types
  • Garbage collection internals for Flash Player and Adobe AIR
  • AS3 fundamentals: Conditionals
  • ActionScript 3 fundamentals: Functions
  • ActionScript 3 fundamentals: Associative arrays, maps, and dictionaries

Products

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • Digital Publishing Suite
  • Elements family
  • SiteCatalyst
  • For education

Download

  • Product trials
  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR

Support & Learning

  • Product help
  • Forums

Buy

  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers

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 © 2013 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

Ad Choices

Reviewed by TRUSTe: site privacy statement