What is “ActionScript”

“ActionScript” is the scripting language of “Flash”.
Through interactive “ActionScript” we can create filming and advanced applications, including connecting your “Flash” movies to a database.

So far, this course has said nothing about it but, I want to give you the basic use of “ActionScript”.
If I ever have spare time I will write a course exclusively on “ActionScript”, but for now you’ll have to make do with basics.

 

The “Stop” action

In the “ActionScript” code, we can add frames, “Button symbols” and “Movie clip symbols”.

As we all know, the “Flash” movie plays automatically from the first to the last frame. When you come to the last frame, the movie repeats itself.

To change this, we use “ActionScript”.

As mentioned above, we can add “ActionScript” code to frames, “Button symbols” and “Movie clip symbols”.
To stop the movie from playing, we put the “Stop” action in the first frame.

Let us again take the “Flash” Movie of my car, driving from right to left across the “Stage”. As soon as we play the movie, it will begin its ride.

To stop it we must add a “Stop” action on the main “Timeline”.

The first thing you do is to create a new layer where you put all the “ActionScript” code.
I call this AS layer (which is an abbreviation of “ActionScript”) and place it on top.
This is not so necessary but, it keeps things a little organized and this way I can find all frames containing “ActionScript” faster.

I select the first frame of the AS layer and open the “Actions”.
The quickest way is to click the F9 key on your keyboard.
This window will be somewhat different, but we currently need nothing of this except clicking the “Script Assist” button and an arrow. This gives us a nice big “Actions” window .

With Frame 1 of the AS layer still selected, type in the code for“Stop ()”;
This code will stop the “Flash” film in the first frame, in other words, the vehicle remains at the far right.
Had this “ActionScript” code placed in eg frame 50, then had the “Flash” movie would’ve played at 50 frames before stopping and the car which would’ve driven halfway across the “Stage”.
For your information:
You can see the top of the “Actions” window “ActionScript” code that you are adding to a frame. If you are working on a button it would be the word button that is displayed.

Now the “Flash” movie is stopped, we must find something to drive the car back.

This can be done by a button

if you dont feel like creating a “Button symbol”, “Flash” has a number of standard “Actions” in its “Library”. You can open it by clicking “Window” in the menubar, choosing “General Library” in the drop-down menu and clicking on “Buttons”

Create a new layer and drag an instance of a button on the “Stage”.
Give it an instance name in the “Properties window”.
If you wish to change or convert anything of this instance on “Stage” through “ActionScript”, you must always give it a name.

We open the back window and add the following code.

A word of explanation:
We begin our code with the name of the instance: “Green”, followed by a period.
The second thing you need to know is that “Flash” has a method called “addEventListener()” method.
A method is something you can do, or rather what “Flash” can do.
Then we open the brackets and tell “Flash” which event it must wait for, before it executes the code, so this is the MouseEvent followed by a period. Then we tell it what this “Mouse Event” is, in this case CLICK. We type a comma, and finally we give a name of the function which “Flash” must perform when these conditions are met.

In this case, I have this function, the name given is “ButtonClicked”.

Then we write the function.

We begin with the word function followed by a space and the name of the function, in this caseButtonClicked.
We open the brackets and type event: MouseEvent then closing parenthesis and type “: Void“.
“Void” is a function that delivers no value. In other words this is a feature that just does something and gives no further information. But you must remember it is only for this course.

Then we determine the function. A function always starts with an open brace and always ends with a closing brace.
Between these two, place the action. In this case play ();

Test your movie

Of course, the film will not repeat because when the play button comes back to frame1 , it gets the command to stop the movie.

If you wish to see this car driving back, click the button again.

The most obvious would be that you create a button to stop the car and one for the car to drive.
Many of you do not have to do this.
Add a button to the “Timeline” and give it an instance name.
Remove the “Stop” the action from the first frame.
Copy and paste the rest of the code, change the name of the instance and adjust function to customize.

Try this out yourself and if it does not work, there is an example in the “Download Files”.

 

Awesome!
You've completed Lesson 44
START NEXT LESSON