Unit 17. Introduction to ActionScript (III)


The Actions

 

  The Actions are predefined functions of ActionScript, in other words: Flash creates them, and we must only use them like it is indicated. We must not even define functions with the same name. The important thing is that they are ready for being used and that they ease the use of this programming language and, moreover, makes us start programming quicker.

Like in the previous case, we will explain the most important Actions. For a more complete reference, we recommend to look at the program help.

 

We'll define the actions writing its head (name + parameters with a generic name) to explain later the meaning of each parameter.

 

Actions - Movie Control

These actions are used, as its name indicates, to control the stream of our movie, this means, to indicate to Flash at every moment what frame has to show, when has to stop, where it must continue etc... Let's see them and we will understand it better:

gotoAndPlay / goto: This action will be, probably the most used when producing your movies. The action consists in moving the reading head to the frame that we indicate to it. The reading head determines what frame of our movie is reproduced at every moment. If, for example, we move it from the frame 1 to the 25, which we will see suddenly the frame 25 and the movie will continue playing from there.

Use:

gotoAndPlay(scene, frame):

scene: It is name of the scene to which we want to send the reading head. It must go between double quotes.

frame: Number or name of the frame where we want to send the reading head. If it is a name, it must go in double quotes, if it is a number, IT DOESN'T.

Example:

gotoAndPlay("Scene2", 7); --> This action takes the reading head to frame 7 of the scene called "Scene2".

 

Play: It begins the reproduction of the movie, generally because something has stopped it.

Use:

Play();

It does not have Parameters.

 

Stop: It stops the reproduction of the movie. It is possible to use it in a frame, when we want to stop the movie in it (because it is a menu, for example).

Use:

Stop();

It does not have Parameters.

 

Actions - browser/Network

These actions have several functions, we'll describe the most important:

fscommand: This action is able to execute certain very powerful commands. The possible commands that it admits are:

- fullscreen: It makes our movie to take the full screen mode. It is very useful for presentations in CD-Rom, for example.

- allowscale: It controls the change of parameters of the objects inserted in the movie when the user stretches the edges of this one (or the page Web in that it is) We want to maintain the proportions? This command allows us to control it.

- showmenu: If you have seen the menu that appears when pressing the right button of the mouse on a movie Flash, surely you have thought about making it disappear... Executing this sentence correctly, we will be able to hide it.

- trepallkeys: It serves to detect all the keys pressings during the reproduction of our movies.

 

All these alternatives, share its use mode, let's see it:

Use:

fscommand("command","true / false")

command: The command to execute (fullscreen, allowscale, etc...)

true / false: Here we must write true or false, according to our will to deactivate or to activate the option.

Example:

fscommand("fullscreen", "true"); -> It activates the full screen mode.

 

getURL: This action is used to open a Web browser and the Web page we would like to.

Use:

getURL(url , window , "variables")

url: Web Address we want access (a window will be opened).

window: OPTIONAL Parameter. Mode in which we want to open the window (in the current window (_self), in another new (_blank) etc...)

variables: OPTIONAL Parameter, can have several. If the page allows it (if it is ASP, PHP etc...) we can send to it variables.

Example:

getURL("http://www.teacherclick.com", "_blank");

loadMovie / loadMovieNum: This action allows to load new movies of Flash or images dynamicaly in our movie (the movie will be loaded only when we indicate).

Use:

loadMovieNum(url , level / destination, variables)

url: Absolute address where the SWF movie or JPEG image is located

level / destination: Level where we will load the movie, considering that the basic level is the 0. Each superior level is located in front of the previous one and takes the control.

variables: OPTIONAL Parameter. We can send variables.

Example:

loadMovieNum("MyMovie2.swf", 0) --> We loaded the movie "MyMovie2.swf" in the main level. We did not send variables.

 

Actions - Conditions

These actions serve to control the logic of the movie. We can say that they allow "to communicate" with Flash to indicate him what it must do before different situations.

For example, now that we know many Actions, but we do not know how to say to Flash "If this happens, do something, and if not, do the other...". Let's see how to say it:

if ... else: If we suppose that the literal translation of if is "if..." and the one of else is "else ...", we suddenly find out that it really is saying: "if (passes a condition) {do this} else {do the other} "

Let's see its Use to understand it better:

Use:

if (condition) {sentence1...} else {sentence2...}

if: It indicates that the action that comes next is conditional

condition: It indicates a condition that MUST to be fulfilled to make the actions indicated in "sentence1" happen. If these are not fulfilled, then what happens is the thing specified in the actions indicated in "sentences2".

In order to fulfill the condition, it must have a result of true, or the one that is the same thing, 1. The importance of the comparison operators and the value that give back comes from here.

sentences1: Set of actions that will happen if the condition is evaluated like true. If there is more than 1, they must be included all BETWEEN THE KEYS

else: It specifies the alternative if the condition is evaluated as false. It is OPTATIVE. If it doesn't exist, and the condition is not fulfilled, nothing would happen, because we have not specified it.

sentence2: Set of actions that will happen if the condition is evaluated like false. If there is more than 1, they must be included all BETWEEN THE KEYS

Example:

if (x == 2) {gotoAndPlay(6); } --> If variable x is equal to 2, then we jump to the frame 2, if not, we don't do anything

if (y > 7) { Stop(); } else {gotoAndPlay(1); } --> if the variable and is greater than 7, we stop the movie, if not, we return to the frame 1.

 



 
   
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.
January-2006.