Flash is not so great at animating stuff. But unless your Web site is just a continuous animation you’re going to have to provide some kind of control to your site user. And, if you provide control to your site user, you’re going to need to use ActionScript to accomplish that.
ActionScript 3 is the preferred version of ActionScript for Flash-based Web sites because it fully takes advantage of the functionality of Flash Player 10. You can still do stuff in AS2 or AS1, but why? You wouldn’t make a new car that only went 55 miles an hour. Make it go 100!! No on will ever use that much speed (legally) but it means that the mid range of speed where the rest of the world drives is fully optimized and not overworking the engine.
OK, Speed Racer© examples aside, here is a rudimentary introduction to ActionScript. We will reference this often.
Statements
A statement is a complete directive that is evaluated in one line. It ends with a semicolon.
A directive is like a command. “Billy, get me the remote.” or “Sally, paint my house.” are directives. It is an order to do something and it’s directed at/with/to someone/something – hence the term directive.

This will evaluate to 11. The PLUS sign is the action and the 5 and 6 are the values to act upon. This is a single directive in a single statement.
A statement will contain a directive (or multiple nested directives) to do something or change something or set something …etc

This will evaluate to 11. However, there are two directives(actions) here. The 5+6 and the trace() command. Flash will evaluate 5+6 as 11 and then send that value to the trace() command. The trace command will, in turn, output the value it receives to the output window when we test this (CTRL+ENTER).

You could split these two directives into two complete statements:

In this case we set the value of the 5+6 directive into a variable (which we’ll cover later) named elEven. We get the same value in the “output” window as above:

Flash will evaluate a statement at run-time, do as it’s told and then move on.
Functions
A Function is a collection of statements. You can place one or many statements inside a function body.
A statement is evaluated immediately at runtime. A function must be called by it’s function name in order for it’s body of statements to be evaluated. The function call is a statement directive. I know. it hurts my brain too.
In order to call a function we must define it first with a function declaration. The declaration does not need to be on a line number ahead of the function call. But it must be on the same or earlier frame number. All ActionScript on a particular frame number executes at the same time. So, as long as your call and declaration occur at the same frame number you could have them on separate layers…if you wanted to do it wrong, though it would still work.
The function declaration is broken up into two parts: a head and a body. You would not get a whole lot accomplished without your head; nor would your head be any good without a body to put thoughts into action. The same is true for functions. Here is the declaration head:

Here is the head with it’s body. Marvel at your creation.

Those two forward slashes is how we “comment” out a line. It’s for adding comments that help us remember what’s going on but we can also use the comment slashes to hide a real statement from flash if we need to diagnose something.
Here is the full function with an actual statement:

When we test nothing will happen though. The reason, if you will remember back a few paragraphs, is that flash will not evaluate statements in a function until the function has been called. We must call the function in order for the statements to be evaluated and executed (run). Here is the full function call and function declaration:

Now if we test this we should get the following in our “output” window:

Flash will perform the function by evaluating the statements in the function. Flash will then evaluate the function’s return value and any surrounding directives outside of the function call.
What’s a “return value”? A return value is basically output from the function. All functions perform some action but the function can also send a value back to where it was called. An example would be a function called <code>ageMe</code> that you call, including the year you were born, and the function returns your age based on the current date. Here’s a simpler example:

Instead of a trace command we are using the key word “return”. This tells flash to return the value or object that is after the word “return” on that statement line BACK to where the function was called. If you could see the actual code running you would find the string “Hey, imma let you finish.”; where the function call doThis(); used to be. Nothing would be sent to the output window because only a trace command can do that.
However, if we place the function call inside of a trace command then we can see the output:


So, when the statement on line 1 is evaluated Flash sees two directives, a function called doThis and a function called trace. It performs the doThis function first, which returns the string “Hey, imma let you finish.” This replaces the doThis function call and then Flash executes the trace function with “Hey, imma let you finish.” as it’s parameter.