This flash snippet is a highly functional
scrolling window, that demonstrates the benefits of conceptualizing
different places for scripts. My functions are in a frame script;
my objects and actions scripts are attached to buttons.
A function is a set of instructions that can be
activated in other sections of code by simply calling the name
of the function or
using it in other instruction sets. The button scripts are attached
to the buttons because the buttons are the starting point for
mouse interaction with them.
The question of "where do scripts go?" is an organizational one--and
a philosophical one, too. A flash scriptor must think about the categories
of his or her flash project. If one has actions that act upon buttons
and they refer to code routines which act upon the flash movie (the whole
project or scene), then where do the code routines or functions get placed?
In computer programming, the flash movie is like a specialized
class file. A class file is a description, in computing code, that
models a
system, whether complex or simple. By class I mean type or category definition.
For instance, if you had a summer cookout class, you might have a barbecue
function
and
data
objects
like
steaks, chicken, roasted vegetables, and beer. The barbecue function
acts upon the steak, chicken, and roasted vegetables and it might use
the beer data object for flavor on the grill.
The question of where do the functions go is answered
by the notion of encapsulation. A class is like a container, or mixing
bowl for ingredients. A set of ingredients cannot all act on the recipe
or work toward the completion of a food item unless it is available
to the mixing function, i.e. in the same bowl of ingredients. We encapsulate
the mixing functions and the data objects or ingredients into the class
and this is how we define the class type: creamed spinach. The name
"creamed spinach" encapsulates the milk and spinach that go into the
recipe along with a mixing procedure that acts upon those ingredients.
The question of where do functions go then appears to
be answered by the fact that a Flash movie is like a code type definition
for vector animation. Each flash file is a definition of vector animation
AND the specific subject matter that it deals with, a factor also detailed
in the naming scheme for the objects in the flash movie. Another thing
is that flash movies contain other classes in the form of objects--symbols.
When we make an object from a symbol, this is a type definition that
we instantiate or make an instance of, and they define the project.
So the flash file is a vector animation type definition that encapsulates
the objects or symbols, object definitions that can be of any subject
matter. The idea here is that a data object can also be a type definition
differing solely in that it is a copy or instance of it. A Class can
have subclasses.
With these distinct layers of components in Flash, you
might ask when you are scripting, is this a general function applicable
to a variety of objects that may use it, or is this a function that
treats specifically an object in the flash movie, treats a button or
movie clip? If it is a general function, then you want a flash movie
(flash file) script. To create this, first create a separate script
channel in the timeline and control-click on the first frame to place
the script. When the movie plays frame one, it gets access to those
generalized functions for acting on the objects.
Events and Buttons, and Encapsulation
How can encapsulation be used to explain button events
or movie clip events? Well, it simply incorporates into objects the
user in the data and procedural model. The user becomes an element
that is accounted for by the programmer, in his or her code. So in
the code, the user, thought of as a class uses buttons or movie clips.
We have events which are modeled in the program. On Rollover is called
when the mouse rolls over the button, this activates the stored procedures
within the code snippet following the button event.
We say that the button is a type definition that has
data (its look and visual characteristics) and procedures, functions,
that act upon it. The button as a type definition encapsulates the
data and procedures. In turn that type definition can be used as a
data object in the Flash movie or class encapsulating the button objects.
So you have a bowl of ingredients with different properties,
and because of what they are specifically coded to do, they resolve
themselves in varying levels of encapsulation. Computer programming
is both a mix or soup, and a definition of properties analogous to
those in chemistry or physical science, that tells, when encapsulated,
or mixed, the interaction between components.
Object Oriented Programming 101: type definitions or
classes consist of data and procedures. The data can be other type
definitions that have their own data and procedures which can have
their own data and procedures. You want interaction between a button
and a function that deals with the general movie? Make a movie script
with a function. Put the function in the first frame to be available
to the entire movie. Have the button event call that function. Encapsulation.
The Soup. Mixing and defining properties for interaction. Computing
is both a set of files or data, and procedures within that data that
have varying orders of other data and procedures encapsulated. The
programmer mixes, and distinguishes how interaction will emerge from
the soup.