| Unit 17. Basic Level. Initial concepts of Programming |
| Introduction to the Programming with ActionScript |
|
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...
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.
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.
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.
- 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 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.
|