To make things easier for those who are new to flash, we will be using actionscript 2.0

Before I explain some action-script, I will briefly describe the flash interface. If you are already familiar with it's basics, you may skip this.

First, we need to start up flash. Once started, you will see the option to make a new flash document, click it. (If you are using flash CS3, choose to use action-script 2.0)
You now have a blank document open. Here are some things you should notice:
At the very top are the basic options (file, edit, view, insert, etc...) I may refer to those options in other tutorials.

Below this is the time-line. the time-line is broken into frames (labeled at the top from 1 to infinite).

You will notice that to the left of the time-line, are the layers. below the layers you see some small buttons to have layers added or deleted.

Below The time-line and layers, is the main window. This is where all images and objects are displayed. You can put images or objects above other images or objects simply by having them placed in a higher layer.

To the left of the main window you see various tools used for objects in the main window such as (select, moves, line creation, rectangle/circle creation, the paint bucket, etc...)

On the very bottom bar (below the main window) you can choose from options such as the main window's size, the frame rate, and the background color.

Now that you know some of the basics of the interface, I can explain some basic action-script. these are the commands I will cover:

[ccN_actionscript]onClipEvent(enterFrame){ }[/ccN_actionscript]

Now, you may ask, where do I type these commands? Well, in action-script 2.0, you can apply script to many objects such as buttons, movie-clips, and frames. to do this, select the object (by clicking it and seeing that it is "highlighted") and press your F9 key. or right click and select "actions".
So, to start this off, go to your tools to the left of the main window, select the rectangle tool and draw a rectangle in the main window. then, choose the black arrow tool(selection/normal cursor) and select your rectangle. Then, you can either right click and select "convert to symbol" or you can press F8. In the popup, write a name for you move-clip and make sure the check-box for "movie-clip" is selected. then press "ok".
you can now add action-script to this movie-clip. left click it once and press F9 or right click it and select "actions".
in the window that pops up type the following:

trace("Hello World");

now, press CTRL + Enter to preview your flash file. you should notice three things.
1. text keeps popping up non-stop
2. you can see "hello world"
3. you see undefined most of the time.
This can all be explained in the code you put into the movie-clip.
I will explain the code line by line:


Because there is only one frame, you will "enterFrame" at whatever speed your frames per second is. (The default is 12, so you whatever you have inside the { } after onClipEvent(enterFrame){ will happen 12 times every second.

[ccN_actionscript]trace("Hello World");[/ccN_actionscript]

The trace command is a useful command for flash developers because it allows us to see when things happen, or what a variable is equal to. It is especially useful because it wont be shown when the document is published. In this case we have ("Hello World"); after it. no matter what you want to output with the trace command, you will always put it in () and end it with ; However, if what you want to output is a string of text, like Hello World, you must put it in double quotes so flash nows that it is just a string of text. hence trace("Hello World");.


again the trace command. The difference here however is that there are no double quotes. because of this, flash interprets "variable_1" as the name of a variable. We have, however, not made a variable so it does not know what value to output. because of this, it will, by default output "undefined". Meaning that the variables is undefined.


This again is the trace command, and again, there are no quotes, so flash will take _global.variable_1 and _global.variable_2 as variable names (that are of course undefined). the difference here though, as I'm sure you have noticed is the "_global." _global. is placed in front of a variables when it is to be used from any place in your flash document. without it, the variable is restricted to the code where it is defined.


this last bracket is used to close off the onClipEvent(enterFrame){ bracket. Everything between those two curly brackets is supposed to happen "onClipEvent(enterFrame)" or, 12 times a second.

Now, lets make this a little more interesting.

Open up the actions for the movie clip you made and add

[ccN_actionscript]var variable_1 = "Hello to you too!";[/ccN_actionscript]

right below onClipEvent(enterFrame){

If you press CTRL + Enter you will see that Hello World and Hello to you too! are both output by the trace commands.

This is because you designated a value for the variable "variable_1"; by using the var command. you made the variable_1 = a string of text by putting the text in double quotes. If you did not use double quotes, it would think Hello to you too was the name of a variable and try to make variable_1 equal it its value (undefined).

Well, now we should finish this off. Exit the actions window for the movie-clip and open the actions window for frame 1 be either right clicking it and selecting "actions" or left clicking it once and pressing F9.

here type the following code:


var a_brake = "over the world!"
_global.variable_1 = "watcha "+"wanna"+" do?";
_global.variable_2 = "take "+a_brake;

now, I will explain this line by line:

[ccN_actionscript]var a_brake = "over the world!"[/ccN_actionscript]

the var command states that there is a variable named whatever comes after it (in the case "a_brake"). at the same time, we can put = #/variable/"text". if you want it to equal a number, do not use double quotes. if you want it to equal a variable, do not use double quotes, but if you want it to equal a string of text, put that string of text in double quotes. You can also split this up. First declare the variable exists by saying "var a_brake" and then latter on in the script you can make it equal to something a_brake = #/variable/"text" .

[ccN_actionscript]_global.variable_1 = "watcha "+"wanna"+" do?";[/ccN_actionscript]

when making a _global. variable, the var command is not needed.
however, everything after it is the same.

here I said it equals "watcha " (the string of text "watcha ") + "wanna" (the string of text "wanna") + " do?" (the string of text " do?"). when adding string of text together, it appends one after the other, meaning _global.variable_1 will equal "watcha wanna do?". because this is an _global. variable, it can be accessed by the script in our movie clip.

[ccN_actionscript]_global.variable_2 = "take "+a_brake;[/ccN_actionscript]

Here, we say that _global.variable2 equals the string of text "take " plus the variable a_brake (it's a variable because there are no quotes around it). because a_brake is a equal to a string of text, it will append it after "take ".

pressing CTRL + Enter should display this.

Be Sociable, Share!