A Primer
Based on JavaScript
Object
-
oriented programming
Everything you do in
ActionScript
does something to some
object*
Some objects in Flash
Movie Clip
Graphic
Button
Objects are defined by classes in AS3
2
*
anything you can manipulate in some way
Class
: a group of items that are similar in some way
Items are called
objects
or
instances
of the class
▪
Objects
can be concrete (like a
button
or
graphic
) or abstract (like a
variable
that is invisible, but hold data)
▪
Objects have two aspects: form (
properties
) and function
(
methods
)
Each
property
and
method
is defined by
Actions
(pieces of code that tell Flash how to manipulate a
target object at any point in your movie).
3
Ball could be considered a
class
of items defined as
“spherical things”
One
object
in this
class
is a movie clip called
Tennis_ball
▪
The
properties
of
Tennis_ball
might be the color
neon green
or a 20
-
pixel diameter
▪
Its
methods
might be bounce, roll, and/or spin
A 2
nd
object
in the ball
class
might be Softball
▪
Properties
white…etc.
4
syntax
variables
constants
statements
assignment statements
keywords
operators
expressions
arrays
procedures
functions
arguments
control structures
loops
conditions
comments
5
control
the
playhead
of a timeline
move
things around
create
and manage user interfaces
play
sounds
control
video
manage
data (xml, lists,
etc
)
communicate
with server
-
side applications (e.g., web
servers)
6
select frame 1
type the following into the
Actions
panel
:
var
message
= "Hello world!";
that line of code constitutes a complete instruction, known
as a
statement
now create three more statements:
var
firstName
= "
your name here
";
trace(message
);
trace ("
Hi there, " +
firstName
+ ", nice to meet you
.");
play
the
movie
-
select
Control
>>
Test Movie
7
ActionScript
notation must end in ;
object.method
(argument);
like
noun.verb
(adjective);
Example 1
root.gotoAndPlay
(2);
this.gotoAndPlay
(2);
gotoAndPlay
(2);
Explanation: This script instructs the
playhead
on the main timeline
(“root” or “this”) to go to and play on frame 2. Identifying “root” or “this”
by name is optional
—
the current timeline is the default, so you could just
say
gotoAndPlay
(2);
8
To write AS on Timeline:
1.
Click on a
key frame
and then press F9.
2.
9
Methods:
play();
stop();
gotoAndPlay
();
gotoAndStop
();
nextFrame
();
prevFrame
();
navigateToURL
();
Properties
currentFrame
currentLabel
currentLabels
totalFrames
10
Reusable content stored in Library
Create
instance
from symbols, and name
Make a pictures slideshow
(SlideShow.fla)
12
1.
Open a Flash file (AS3.0)
2.
Import
pics
to library (File
-
>Import)
3.
Convert the
pics
to Movie Clip
(Optional)
4.
Make
keyframes
and place a pic to every
Keyframe
13
5.
Create a button symbol and put it in a new layer
6.
Make two instances (next,
prev
) from the button
symbol
7.
Give an instance name “
nextButton
” and another one
“
previousButton
”
14
Create a new layer and name it, say, “AS3”
Write code on the
keyframe
of the AS3 layer
15
1.
stop();
2.
nextButton.
addEventListener
(
MouseEvent.CLICK
,
onNextButtonClicked
);
3.
previousButton.
addEventListener
(
MouseEvent.CLICK
,
onPreviousButtonClicked
);
4.
function
onNextButtonClicked
(
e:
MouseEvent
):
void
{
5.
if (
currentFrame
==
totalFrames
) {
6.
gotoAndStop
(1);
7.
} else {
8.
nextFrame
();
9.
}
10.
}
11.
function
onPreviousButtonClicked
(
e:
MouseEvent
):void {
12.
if (
currentFrame
== 1) {
13.
gotoAndStop
(
totalFrames
);
14.
} else {
15.
prevFrame
();
16.
}
17.
}
16
1.
stop();
2.
// add an event listener to the next button
3.
nextButton.
addEventListener
(
MouseEvent.CLICK
,
onNextButtonClicked
);
4.
// add an event listener to the previous button
5.
previousButton.
addEventListener
(
MouseEvent.CLICK
,
onPreviousButtonClicked
);
6.
// a function that goes to the next frame when the next button is clicked
7.
function
onNextButtonClicked
(
e:
MouseEvent
):
void
{
8.
if (
currentFrame
==
totalFrames
) {
9.
gotoAndStop
(1);
10.
} else {
11.
nextFrame
();
12.
}
13.
}
14.
// a function that goes to the previous frame when the next button is clicked
15.
function
onPreviousButtonClicked
(
e:
MouseEvent
):void {
16.
if (
currentFrame
== 1) {
17.
gotoAndStop
(
totalFrames
);
18.
} else {
19.
prevFrame
();
20.
}
21.
}
17
Enter the password to open this PDF file:
File name:
-
File size:
-
Title:
-
Author:
-
Subject:
-
Keywords:
-
Creation Date:
-
Modification Date:
-
Creator:
-
PDF Producer:
-
PDF Version:
-
Page Count:
-
Preparing document for printing…
0%
Comments 0
Log in to post a comment