ActionScript 2.0 Classes Dr. Scott D. Lipscomb

laborermaizeSoftware and s/w Development

Jul 4, 2012 (5 years and 4 months ago)

251 views

November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
1
1
Object
Object
-
-
Oriented Design:
Oriented Design:
Extending Flash with
Extending Flash with
ActionScript 2.0 Classes
ActionScript 2.0 Classes
Dr. Scott D. Lipscomb
Dr. Scott D. Lipscomb
Northwestern University, School of Music
Northwestern University, School of Music
Music Education & Music Technology
Music Education & Music Technology
http://faculty
http://faculty
-
-
web.at.northwestern.edu/music/lipscomb
web.at.northwestern.edu/music/lipscomb
/
/
2
2
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
Macromedia Flash allows the
Macromedia Flash allows the
developer to
developer to


create simple to complex interactive multimedia,
create simple to complex interactive multimedia,
greatly facilitated by an intuitive graphical user
greatly facilitated by an intuitive graphical user
interface (GUI) & built
interface (GUI) & built
-
-
in
in


behaviors
behaviors




cross
cross
-
-
platform, cross
platform, cross
-
-
browser compatibility
browser compatibility
wrap a wide variety of media types into a
wrap a wide variety of media types into a
web
web
-
-
ready
ready
presentation format (SWF)
presentation format (SWF)


images, sounds, animations, etc.
images, sounds, animations, etc.
extend the program
extend the program


s capabilities significantly by
s capabilities significantly by
using ActionScript
using ActionScript
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
3
3
Creating Animation
Creating Animation
A simple example
A simple example
01soundCrash_template.fla
01soundCrash_template.fla
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
4
4
Going to the
Going to the


next level
next level


Danger, Danger
Danger, Danger


Warning, Will Robinson!!
Warning, Will Robinson!!
5
5
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
Flash Comes of Age
Flash Comes of Age
MX 2004 introduces ActionScript 2.0
MX 2004 introduces ActionScript 2.0


Object
Object
-
-
oriented programming (OOP)
oriented programming (OOP)
techniques become are much more elegantly
techniques become are much more elegantly
integrated
integrated
closer to industry standard programming
closer to industry standard programming
languages like Java, C++, or C#
languages like Java, C++, or C#
It is now possible to create your own
It is now possible to create your own
classes in Flash or to
classes in Flash or to


easily
easily


alter the
alter the
behavior of classes distributed with the
behavior of classes distributed with the
program
program
6
6
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
ActionScript 1.0
ActionScript 1.0


2.0
2.0
(
(
Moock
Moock
, 2004)
, 2004)
relatively little new runtime functionality
relatively little new runtime functionality
radically improves OOP development
radically improves OOP development


formalizes OOP syntax & method in the Flash
formalizes OOP syntax & method in the Flash
environment
environment
adds the
adds the


class
class


keyword for creating classes
keyword for creating classes
adds an
adds an


extends
extends


keyword to establish inheritance
keyword to establish inheritance


getter
getter


and
and


setter
setter


syntax for setting object properties
syntax for setting object properties


public
public


and
and


private
private


keywords determine access to object
keywords determine access to object
properties
properties
requires
requires
that classes be defined in external
that classes be defined in external


.as
.as


files
files


these files can be created and edited in an external
these files can be created and edited in an external
text editor or using the
text editor or using the


Professional
Professional


version of Flash
version of Flash
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
7
7
OOPs
OOPs


I did it again!*
I did it again!*
What is object
What is object
-
-
oriented
oriented
programming?
programming?
*Perhaps the only Britney
Spears quote you’ll hear
during the conference.
8
8
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
OOP is
OOP is


a different approach to programming
a different approach to programming
designed to make complex applications
designed to make complex applications
more manageable
more manageable


breaking programs down into self
breaking programs down into self
-
-
contained,
contained,
interacting, and reusable modules
interacting, and reusable modules
adds a level of conceptual organization to
adds a level of conceptual organization to
a program
a program


groups related functions & variables together
groups related functions & variables together
into separate classes
into separate classes
9
9
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
OOP Concepts
OOP Concepts
class
class


a self
a self
-
-
contained software module
contained software module
that contains related functions and
that contains related functions and
variables
variables


methods
methods


a class
a class


s capabilities (functions)
s capabilities (functions)


properties
properties


a class
a class


s data values (variables)
s data values (variables)
public
public


accessible from anywhere in the program
accessible from anywhere in the program
private
private


accessible only from within the class (or
accessible only from within the class (or
its subclasses)
its subclasses)
object
object


an instantiation of a class
an instantiation of a class


instance
instance


a specific incarnation of an object
a specific incarnation of an object
10
10
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
OOP Concepts
OOP Concepts
(continued)
(continued)
encapsulation
encapsulation


maintaining private properties
maintaining private properties
and internal code isolated from the rest of the
and internal code isolated from the rest of the
program
program


as long as method names, parameters, & return
as long as method names, parameters, & return
values remain the same, changes can be made to the
values remain the same, changes can be made to the
class without necessitating changes to the
class without necessitating changes to the
program(s
program(s
)
)
data types
data types


used to impose limits on what can
used to impose limits on what can
be stored in a variable, used as a parameter, or
be stored in a variable, used as a parameter, or
passed as a return value
passed as a return value


results in significantly improved debugging & error
results in significantly improved debugging & error
tracking within the Flash environment
tracking within the Flash environment
11
11
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
OOP Concepts
OOP Concepts
(continued)
(continued)
inheritance
inheritance


allow one class to adopt the
allow one class to adopt the
method & property definitions of another
method & property definitions of another


can use Macromedia
can use Macromedia


s classes as a source
s classes as a source
packages
packages


directories that contain groups of
directories that contain groups of
classes
classes


an easy way to organize your class files on your hard
an easy way to organize your class files on your hard
drive
drive
compilation
compilation


occurs when an OOP application
occurs when an OOP application
is exported as a Flash movie (SWF)
is exported as a Flash movie (SWF)


potential errors are identified during this process
potential errors are identified during this process
12
12
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
Building an OOP from Scratch
Building an OOP from Scratch
create one or more classes
create one or more classes
instantiate objects from those classes
instantiate objects from those classes
using ActionScript, tell the objects what to
using ActionScript, tell the objects what to
do
do
13
13
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
Using Macromedia
Using Macromedia


s Classes:
s Classes:
Sound object
Sound object
properties
properties


duration
duration
in milliseconds
in milliseconds


position
position
in milliseconds
in milliseconds
methods
methods


attachSound
attachSound
()
()


getBytesLoaded
getBytesLoaded
()
()


start() or
start() or
start([offset
start([offset
])
])
offset in
offset in
seconds
seconds


stop()
stop()


setVolume
setVolume
()
()


setPan
setPan
()
()
14
14
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
Using Macromedia
Using Macromedia


s Classes:
s Classes:
MovieClip
MovieClip
object
object
properties
properties


_alpha
_alpha


_
_
currentframe
currentframe


enabled
enabled


_height & _width
_height & _width


_name
_name


_rotation
_rotation


_visible
_visible


_x & _y
_x & _y


_
_
xscale
xscale
& _
& _
yscale
yscale
methods
methods


attachMovie
attachMovie
()
()


getBytesLoaded
getBytesLoaded
()
()


getBytesTotal
getBytesTotal
()
()


getURL
getURL
()
()


gotoAndPlay
gotoAndPlay
()
()


gotoAndStop
gotoAndStop
()
()


play()
play()


nextFrame
nextFrame
() &
() &
prevFrame
prevFrame
()
()


stop()
stop()
15
15
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
Instantiating a Class
Instantiating a Class
Basic (AS 1.0)
Basic (AS 1.0)
mySound
mySound
= new Sound();
= new Sound();
New & Improved (AS 2.0)
New & Improved (AS 2.0)
var
var
mySound:Sound
mySound:Sound
= new Sound();
= new Sound();
This is the ActionScript equivalent to
dragging a symbol (class) onto the stage
(creating an object instance).
It is possible to create multiple objects
from a single class.
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
16
16
Dot Syntax
Dot Syntax
Setting properties &
Setting properties &
calling methods
calling methods
17
17
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
Lingo Scripting (verbose)
Lingo Scripting (verbose)
on
on
exitFrame
exitFrame
if
iflevelslider=
TRUE then
TRUE then
if the
if the
locV
locV
of sprite 116
of sprite 116>
362 then set the
362 then set the
locV
locV
of sprite 116 to 362
of sprite 116 to 362
put the
put the
locV
locV
of sprite 116 into level
of sprite 116 into level
set the
set the
soundlevel
soundlevel
to
to(
362
362-
level
level) /
13
13
set the
set the
locH
locH
of sprite 116 to 559
of sprite 116 to 559
end if
end if
go to the frame
go to the frame
end
end
exitframe
exitframe
from Sinewave.dir
18
18
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
ActionScript
ActionScript


Dot Syntax
Dot Syntax
on
on
clipEvent(exitFrame
clipEvent(exitFrame
){
){
if
iflevelslider==
TRUE {
TRUE {
if sprite(116)._y
if sprite(116)._y >
362{
362{
sprite(116)._y = 362;
sprite(116)._y = 362;
}
}
level = sprite(116)._y;
level = sprite(116)._y;
set the
set the
soundlevel
soundlevel
to
to(
362
362-
level
level) /
13
13
sprite(116)._x = 559;
sprite(116)._x = 559;
}
}
gotoAndPlay(_currentframe
gotoAndPlay(_currentframe
);
);
}
}
19
19
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
Setting Properties &
Setting Properties &
Calling Methods in ActionScript
Calling Methods in ActionScript
// instantiate the Sound object
// instantiate the Sound object
var
var
mySound:Sound
mySound:Sound
= new Sound();
= new Sound();
// attach a sound
// attach a sound




linkage
linkage


necessary
necessary
mySound.attachSound(
mySound.attachSound(


cool_song
cool_song


);
);
// set sound level between 0
// set sound level between 0
-
-
100
100
mySound.setVolume
mySound.setVolume
= 85;
= 85;
// initiate playback
// initiate playback
mySound.start
mySound.start
();
();
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
20
20
Macromedia
Macromedia


s Inconsistency
s Inconsistency
yup
yup


they too are imperfect!
they too are imperfect!
21
21
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
The Problem
The Problem
Sound object (ms vs. sec)
Sound object (ms vs. sec)


atmi2005_macromedia.fla
atmi2005_macromedia.fla
problem fixed (hardwired)
problem fixed (hardwired)


atmi2005_macromedia_fixed.fla
atmi2005_macromedia_fixed.fla
creating a class
creating a class


sdlSound.as
sdlSound.as
(
(
expanded version
expanded version
)
)


atmi2005_bare.fla
atmi2005_bare.fla
adding a package
adding a package


atmi2005_bare_package.fla
atmi2005_bare_package.fla
22
22
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
The Future
The Future
Playback Control
Playback Control


atmi2005_playbackControl.fla
atmi2005_playbackControl.fla
BubbleMachine
BubbleMachine
(Lipscomb & Jacoby, 2004)
(Lipscomb & Jacoby, 2004)


BubbleMachine.swf
BubbleMachine.swf


version 2.0 in progress
version 2.0 in progress
23
23
November 4, 2005
November 4, 2005
ATMI 2005
ATMI 2005
-
-
Qu
Qu
é
é
b
b
é
é
c City
c City
Contact Info
Contact Info
Dr. Scott D. Lipscomb
Dr. Scott D. Lipscomb
Northwestern University
Northwestern University
Music Education & Music Technology
Music Education & Music Technology
lipscomb@northwestern.edu
lipscomb@northwestern.edu
http://faculty
http://faculty
-
-
web.at.northwestern.edu/music/lipscomb/
web.at.northwestern.edu/music/lipscomb/