You are on page 1of 4

ActionScript

MouseEvents (with Buttons)(press, release, releaseOutside,rollOver, rollOut, dragOver, dragOut,


keyPress)

Keyboard Events (with Buttons) (Delete, Backspace, Up, Down, etc….)

Movie Clip Events (load, unload, enterFrame, mouseDown, mouseMove, mouseUp, keyDown,
keyUp, data)

Timeline Control (gotoAndPlay, gotoAndStop, play, stop, stopAllSounds, prevScene, nextScene,


prevFrame, nextFrame)

Scenes

Scenes play from top down. But you can also target a button or frame to go to a specific scene.
For example:

on (release) {
gotoAndPlay(“Scene 1”, 1);
}
“’Scene 1’” refers to the scene and the “1” refers to the frame.

Targeting Movie Clips and Dot Syntax

myMovieClip_mc An instance name. (_mc at the end helps you remember it’s a move Clip. Use
_bn for button, for example.)

myMovieClip_mc. How the instance name appears in the ActionScript. This is called a target,
or a target path.

For example:

on (release) {
myMovieClip_mc.stop();
}

_root. The main timeline in the ActionScript.

For example, if you want to code a button to make the myMovieClip_mc movie clip start playing
at it’s own frame 3, you would type:

on (release) {
_root. myMovieClip_mc.gotoAndPlay(3);
}
Loading Movies

loadMovieNum Can be added to a frame or object. Loads a .swf file into your main Timeline (or
wherever you decide you want it).

For example:

loadMovieNum (“Animation.swf”, 1);

This loads the .swf file “Animation.swf” into the main timeline. The “1” refers to the level since
you can have many, many movies loaded into one frame in the timeline. The main timeline is “0”,
so generally you don’t want to use this number.

For example:

loadMovieNum (“Foreground.swf”, 3);


loadMovieNum (“Middleground.swf”, 2);
loadMovieNum (“Background.swf”, 1);

You can also unload movies if you don’t want them to block other movies.

For example, I’ve loaded a movie of the oldest child on layer 3. I have a button that I want to put
the middle child there and hide the oldest child:

on (release) {
loadMovieNum (“MiddleChild.swf”, 2);
unloadMovieNum (3);
}

For Web Distribution – Basic Preloader

Make two blank keyframes. Write on the first “loading…”. On the next one, place a large-ish
jpeg image.

On the first frame, put the following action:

if (_framesloaded>=_totalframes) {
gotoAndPlay(2);
} else {
gotoAndPlay(1);
}
Go to Control>Test Movie. Then go to View>Download Settings and select DSL. Then go to
View>Simulate Download. Sweet! How do you think this action worked?
The Basic Grammar of ActionScript

Objects Things you create in flash including sound, graphics, text, and numbers, which you can
also use to control aspects of the movie.

Classes All objects belong to some type of class including the Math class, the Sound class, the
Video class, etc.)
For example, you have four objects: a Ford, a Tree, Dick and Jane and Spot. The Ford belongs to
the Car class, the Tree belongs to the Tree class, and Dick and Jane both belong to the People
class. Spot thinks he’s a person, so he’s People class also.

Properties Each class has a set of pre-defined properties. For example the MovieClip class
includes properties such as _width, _height, and _rotation. Dick and Jane have the _height,
_weight, _sex, and _hairColor properties.

Methods Since Objects can do things, each class has its own set of things it can do, which are
called Methods. For example the Sound class has a setVolume method. Dick and Jane have the
Run method.

Dot Syntax Dots are used to help define Objects from their Properties and Methods. For
example:

Dick.weight = 170
Jane.height = 63

If we want to say spot runs, we would say: Spot.run();

The parentheses hold the properties for the method, for example: Spot.run(fast);

; Ends a specific ActionScript statement.


{} Groups related ActionScript statements.
, Separates a series of parameters.

Variables
There are many types of variables, but the most common are Number (a numeric value), Sting (a
series of letters or words), and Boolean (a true/false value). Examples of each:
var winningScore:Number = 50;
var youWin:String = “Congratulations, you win! You’re a winner!”;
var ballinBasket:Boolean = true;

Expressions and Strings


These are a series of statements made before Flash can figure the conclusion out. An expression
can include variables, strings, properties, and objects that have to be figures. A string is just a
calculation, such as “a + b”. Examples of expressions and strings are:
var dicksArea:Number = dickLength * dickHeight;
spotYears = 7 * age;
spotSpeed = distance/time;
Functions
Functions group related ActionScript statements to perform a specific task. Instead of having to
write a bit of code over and over, functions help set up a repeated task.
For example on Saturdays, Dick, Jane and Spot play ball:

Dick.pitchBall();
Jane.hitBall();
Spot.run();

But they do this every Saturday; so setting up a function would make this repeated task easier:

function Saturday() {
Dick.pitchBall();
Jane.hitBall();
Spot.run();
}

You can also assign functions to objects such as buttons. For example, we have a button instance
named “saturday_bn” and on pressing it we want to perform the above-mentioned function. So
the code would be:

saturday_bn.onPress = function() {
Dick.pitchBall();
Jane.hitBall();
Spot.run();
};

With these grammar rules in hand, go out and try to find an action that you would like to recreate.
The easiest way is to copy Action Script from online and paste it into Flash creating movie clips,
buttons and graphics and naming the instances correctly so that the code will work. Then you can
start tweaking the graphics and code to get it to do what YOU want!

You might also like