erin n pierce // creativity from the ground up


ActionScript Basics: Terms Defined

Terms, defined

There are some terms, some of which we have covered, that will be useful to have a general and basic understanding of.

  1. Instances & Instance Names
    When we create symbols, existing in the Library and drag them onto the stage, we create an instance of that symbol. If we will be referencing an instance in our ActionScript, we must name that instance. You name your instances in the Properties Panel.
    picture-1
  2. Statements
    A statement is like a sentence only rather than the expression ending with a period it ends with a semi-colon (";"). Example:
    var theDog;
  3. Variables & Data Types
    Variables are containers; they are vessels used to store various bits of information. There are many types of data. Here are a few:

    Number
    These can be positive, negative, integer or decimal (floating point) numbers.

    var myAge:Number = 52;

    //comments are indicated by using two slashes ... these are good to use. they will help you remember what a line of code means

    /*
    if you will be writing extra, you
    can use a slash + a star and that will
    give you the ability to comment a longer
    description or block of code

    */

    Boolean (true/false)
    var myStatement:Boolean = false;

    String
    var myName:String = "Bob Saget"; // set value of the myName variable equal to Bob Saget

    NOTE: The way in which data is stored is very important. For example, these are not equal:


    var myAge:Number = 52;
    var myAge:String = "52";

  4. Functions
    Functions allow for reusing a block of code.

    function myFirstFunction() {
         trace("hello");
    };
    myFirstFunction();

    Many functions are built into Flash. trace(); stop(); and gotoAndPlay(); are three of the most common.

  5. If Statements

    An if statement is a conditional statement…if you’ve ever taken a logic class, these are similar type statements…
    First, write out what you’d like to check:

    // if the x property of the dog movie clip is equal to 50, then trace "x equals 50"


    if (dog_mc.x == 50) {
         trace("x equals 50");
    }

    You can also have it do something else if the condition is not true using if / else statement.

    // if the x property of the dog movie clip is equal to 50, then trace "x equals 50", otherwise, trace "x does not equal 50"


    if (dog_mc.x == 50) {
         trace("x equals 50");
    } else {
         trace("x does not equal 50");
    }

  6. Operators
    The double equal sign (==) in our if statement is called an Operator. Operators tell the statement how to compare the two variables. Here are some other operators and their descriptions:

    Operator Description
    == equals
    != does not equal
    > greater than
    >= greater than or equal to
    < less than
    < = less than or equal to
    && and*
    || or*

    *Here are examples of how you would use the && and || operators:

    AND Operator: &&
    // if the x property of dog mc is equal to 50 AND the y property is equal to 50, trace "x and y equal 50"

    if ( (dog_mc.x == 50) && (dog_mc.y == 50) ) {
         trace("x and y equal 50");
    }

    OR Operator: ||
    // if the x property of dog mc is equal to 50 OR the x property is equal to 100, trace "x equals 50 or 100"

    if ( (dog_mc.x == 50) || (dog_mc.x == 100) ) {
         trace("x equals 50 or 100");
    }

  7. Loops
    Loops are used to execute a specific set of items a specific amount of times. There are several types of loops, the most common of which is the For loop.

    for ( var i:Number = 1; i < = 10; i++ ) {
         trace(i);
    }

    The first item in the for loop is establishing the counter. We have to declare the variable (var i), the variable type (:Number) and give it a value ( = 1;). This will be the beginning or starting value of the counter.

    Next we need to establish the condition. How many times does the for loop need to run? So we state the the variable i is less than or equal to 10.

    The final piece in the for loop is the action. This tells the loop whether to increase (i++) or decrease (i--). Most often you will only need to increase.

    Try changing the initial counter number, the final number or the action…see what happens!

Resources

Variables & Data Types
Functions
For Loops
General tutorials

Bookmark and Share

Leave a Reply

name*

email* (will not be published)

website

comments