Unit 17. Basic Level. Initial concepts of Programming

Introduction to the Programming with ActionScript


 We've catalogued this theme as "basic", but the suitable word would be "necessary". Although the objective of this theme is not teaching programming, we can't overpass certain concepts related to it; they must be known to be able to understand the ActionScript. Then, we are going to explain some fundamental concepts, necessary to approach the programming by ActionScript.

Script: Code written in any programming language that implements a certain task. For example, to go to the next frame when pressing a Flash button, the necessary ActionScript code is a script.

Variable: We are going to explain the interpretation of the variable term in programming by a simple example.

If we have the expression:      x = 3;

We have that x is a variable that takes the value 3. It is called variable because it can change its value at any moment during the execution of our Flash movie. All the data, which are normally handled are variables (except some constants, for example, the number 3). So, in this way, a name is a variable (of a string of characters type), a last name would be also a variable, as well as the address, the telephone etc...

Expression/Sentences: Set of operators, constants, variables or actions. They cause a determined result or a certain action and ALWAYS must be ended by ';' (point and comma).

Function: A function is a portion of code that has a certain name and that does a concrete operation. For example, the following definition of function:

function IncreasesX(x) {

x = x + 1;


In this function we take the variable value "x" and add "1" to its value. If we want to execute it in some place of our movie, it would be enough to write: "IncreasesX(variable)".

The definition of the function (that is the code shown above) must be written BEFORE calling it.

Action: Flash calls Action to the built-in functions that do not need predefinition to be used. Therefore it is enough to write the call to the function. These actions will be used mostly because they are extremely easy in use and very powerful. The actions appear in the Panel Actions and they can be inserted in our code by a simple click of mouse.

For example "gotoAndPlay(3)" is an action that causes that Flash starts executing the frame 3.

Now that we are familiar with the function definition, we'll also have to understand, that Flash has defined somewhere the function "gotoAndPlay" (as we have done previously with the function "IncreasesX") and written a code that causes the commented effect. Luckily all this has not to worry us, Flash is in charge of everything. It is enough to know the actions and how to use them.

Parameter: A parameter is a variable that is an input or an output for an action or a function. See an example to clarify this definition:

We have the following definition of function:


function Sum5(p_input, p_output) {

p_output = p_input + 5;



Let's imagine that we have a variable x that it is equal to 7 and another variable y that we want to be equal 7 + 5. We would execute the function "Sum5" in the following way: Sum5(x, y). We are going to see what exactly makes the function with the parameters x and y.

When executing "Sum5(x, y)", Flash searches for the function definition that are called Sum5, it will immediately find the definition that we've written above, (that must be written in some part of our movie BEFORE the execution of "Sum5(x, y)"). When it is done, Flash verifies that the executed function COINCIDES with the head of the definition; this head includes the name of the function and all that comes with the parenthesis. In our case, the head would be "Sum5(p_input, p_output)"

The NAME of the function and the number of parameters MUST coincide, these ones will be variables or values separated by comas.

As we have 2 parameters in each side, everything coincides and is passed to execute the function. The executed function will be "Sum(x, y)", and so its execution will be:


function Sum5(x, y) {

y = x + 5;



After executing this function, y will take value of x plus 5. That is just what we wanted.

The variable 'x' has acted as an input parameter, because it contributes a data to the function, the value ' y’ starts being passed into the function, but it is an output parameter because of being modified INSIDE the function and then returned back.

Object Oriented Programming (OOP): ActionScript is an OO language; this means that the information is organized in groups designed as classes. When we want to use a class in our movie, we use an instance of it, named OBJECT. The objects, and thus, the classes have Properties (characteristics) and Methods (behaviors). Let's give 2 examples to clarify this:

- The Person object has:

        - Properties: Name, age, height...

        - Behaviors: speak, run, jump...

- the Movie Clip object has:

        - Properties: color, width, height...

        - Behaviors: gotoAndPlay, Stop, Play, LoadMovie...

Obviously the first object is just didactic; the second object is an object of Flash, and probably the most important...


We can find the objects also in the Actions Panel, its use is easy. Let's see an example:

We have the object Clip1, that is an instance of the MovieClip Class and so far, it has the same Properties and Methods.

- Clip1._height = 20;

With the previous line, we are saying to Flash that the object Clip1 has a height of 20 (Flash will immediately modify it in the movie). The syntax of Flash establishes that the separator "._" must exist, it is not worth describing why. It will be always, thus we'd better remember it.

- Clip1.Play();

This action will implement the Play method, which belongs to MovieClips, and causes the timeline start from the Clip1. You must notice that here the separator is not "._" but "."

We already know the Flash 8 "basic" concepts. If we think about that, we can modify the height of a movie object with only 1 line IN RUNTIME MODE (and not while we created it as up to now).

We will be able to give more live to our animations and to obtain a total interactivity with the user. We will be able to obtain to a complete multimedia movie!


The knowledge and understanding of these concepts are not a requirement to start programming with ActionScript, an intuitive programming is a very common practice in this type of languages.

In this tutorial we recommend to know what is being made at each moment and what every item means; the results will constantly justify the initial effort during our learning in ActionScript, with clear understanding all the above and some work, we will soon become expert programmers and then the intuition will stop being useful...


Legal warning: Authorised on-line use only. It is not allowed the use of these courses in companies or private teaching centres.
© aulaClic. All rights reserved. Reproduction in any form whatsoever is prohibited.