g
Printer Friendly Version

editor  
BellaOnline's Flash and Animation Editor
 

Naming Variables and Other Syntax Rules for ActionScript

In a previous tutorial, we discussed how to create a variable in FlashR ActionScript 3. You learned that you can use the var keyword to define a variable. In this tutorial, you will learn some rules for naming your variables as well as some basic syntax rules for ActionScript.

var name_of_variable = value;

Basically, you can give any name to your variable but there are a few rules that you need to follow.

  1. Each variable name must be unique which means any name can only be used once.

  2. Variable names are case-sensitive which means that a capital letter is not the same as a lowercase letter. For example, "CAT" is not the same as "cat".

  3. A variable name cannot begin with a number.

  4. Variable names can contain only numbers, letters and the underscore.

  5. Some words are already used by Flash and cannot be used for any other purpose. These special words are called keywords. For example, the "word" var is a keyword and cannot be used as a name for your variable.

Since we are talking about rules, let's take a look at a few basic syntax rules for ActionScript.

  1. Each line of code ends with a semi-colon.

    If you take a look at the line of code above, you will notice that it ends with a semi-colon. A semi-colon is used to end a line of code much like a period ends a sentence.

  2. Parenthesis ( )
    Brackets [ ]
    Curly Brackets { }

    Parenthesis, brackets and curly brackets are used in pairs. Every opening parenthesis, bracket or curly bracket must have an accompanying closing parenthesis, bracket or curly bracket.

  3. Strings and quotation marks.

    A sentence such as "My name is Mary." is called a string. In ActionScript, strings must be enclosed within quotation marks. When you place a string between quotation marks, you are telling the program where the string begins and ends. The first quotation mark begins the string and when the program encounters a second quotation mark, it knows to end the string.

  4. Comments

    Every programmer has his or her opinion as to what information should be included within the program code. Most programmers add comments with their code in order to remind themselves, and anyone else, what the code does and how it does it. When deciding what information to include ask yourself what you would need to be told about the program if someone else had written the program and now you were asked to run and maintain it.

    If your comment is only one line, you will begin that line with two backslashes.

    // Your comment goes here

    If your comment has more than one line, you will begin the comment with "/*" and end it with "*/".

    /* First line of comments.
    Second line of comments. */



Flash and Animation Site @ BellaOnline
View This Article in Regular Layout

Content copyright © 2013 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact Diane Cipollo for details.



| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor