Undo command works (the Undo feature is
accessible by pressing Ctrl+Z). The default,
Document-level Undo, means that every time
you undo (by pressing Ctrl+Z), you go back
to the state before the last change. Perhaps
this is the most intuitive behavior. However,
the other option, Object-level Undo, is very
useful. With this option, if you make changes
while inside one movie clip and then make
changes to another movie clip, you can
return to the first clip and press Ctrl+Z to
undo the last thing you did in that clip! It’s
the way Flash used to work (before version
MX2004), and it’s back as a preference.
The margins for your text fields are also
easier to modify in Flash 8. You can now
grab any one of the six handles, as shown in
Figure 1.6. In previous editions, there was
only one special margin-changing handle;
dragging any other handle scaled and
stretched the text rather than the text field. In
Flash 8, if you want to scale the text, you can
use the Free Transform tool or the Properties
panel’s W (width) and H (height) fields.
FIGURE 1.6
Drag any handle on a text field to modify the
margin width in Flash 8.
CHAPTER 1: Exploring Flash 8
14
In addition to the previously mentioned fact
that gradients can be applied to strokes,
gradients also sport a new overflow setting
(accessible in the Color Mixer panel). An
Overflow setting of Extend makes your gradi-
ent fade off infinitely; a setting of Repeat lets
the gradient fade from the beginning to the
end and then repeat and fade from the begin-
ning to the end; a setting of Reflect fades the
gradient from the beginning to the end, fades
it back up to the beginning, and continues to
fade it up and down. Another change to the
way gradients work in Flash 8 is that radial
gradients support a focal point, which means
you can create oblong off-center radial
gradients.
Some of the new Flash 8 features appear
subtle or esoteric—and they are. Although the
9-slice feature can be hard to see initially, it’s
quite powerful. When you select the Enable
Guides for 9-slice Scaling option in a movie
clip’s Symbol Properties dialog box (shown in
Figure 1.7), you are given four special guides
that make a tic-tac-toe pattern on the clip’s
contents. (The guides are editable only while
you’re editing the symbol from the Library—
that is, not by double-clicking an instance on
the stage.)
The contents of your clip in the four outer
squares don’t get scaled when the clip is
scaled. The midsections stretch as needed but
not the corners. This means you can use a
single symbol scaled to multiple sizes and
dimensions, but the corners won’t stretch or
appear distorted. You can see the difference
between shapes scaled in various ways with
9-slice scaling in Figure 1.8. Notice how the
word
close
doesn’t appear stretched even
though the clip’s width and height vary.
What’s New in Flash 8
15
FIGURE 1.8
The same symbol scaled to different dimen-
sions, yet the corners don’t scale.
FIGURE 1.7
The Enable
Guides for 9-slice Scaling
option lets you identify
which portions of your clip
shouldn’t scale (the four
corner squares).
One drawback of the Enable Guides for 9-slice Scaling
option is that it doesn’t work when your clip contains
nested clips.Everything inside the movie clip on which
you want 9-slice scaling to work must be plain shapes
(not clip instances).
NOTE
Flash Player
Interestingly, it took a separate team about
the same size as the team that built Flash 8
Professional just to build the new Flash
player! Flash (the authoring tool) just creates
.swf
files, but the Flash player has to render
those
.swf
files—plus work with all kinds of
browsers on different operating systems. And
it does all this with a file size under 1MB. My
point is that the Flash player makes many of
the new features possible. For example, Flash
player 8 now lets you load
.png
or
.gif
files.
You don’t even need to author your applica-
tion in Flash 8 to take advantage of this
feature, but your users will need the Flash
player 8 to properly load the content of your
files.
This also means that, if you want to employ
one of the new Flash 8 features, your users
must have the Flash player 8 plug-in
Two ways to face the prospect of forcing a
plug-in upgrade on your users are to look at
which new features you want (or need) and
to look at the upgrade experience the users
will have to endure. Every Flash version has
some killer feature that—for the right
project—makes an upgrade requirement
worthwhile. I’d imagine the video quality or
alpha channels will be enough to convince
many users to make the leap to Flash player
8. Only you can answer whether a new
feature is profound enough or saves you
enough time in production to require Flash
8—but there’s a lot of new stuff that could
easily tip the scale.
The upgrade process to Flash player 8 has
been vastly improved through what’s called
Express Install. If your user has Flash player
6.0r65 or later, he already has an integrated
feature you can trigger to install Flash player
8 inline. That is, the user doesn’t have to
download something, quit the browser, run
an installer, and so on. He simply clicks Yes
in a security dialog box that appears right
inside the Flash application (shown in Figure
1.10); a new browser window opens with
your content, and Flash player 8 has been
installed!
FIGURE 1.10
The inline Express Install dialog box
appears inside your Flash application.
CHAPTER 1: Exploring Flash 8
16
installed. One nice new feature when plan-
ning to deliver to an earlier version of the
Flash Player is that you’re given feedback (as
to which features are not available) while
authoring. Say you select File, Publish
Settings; click the Flash tab; and pick an older
target Flash player version (such as Flash
player 7). In that case, any newer Flash 8
features that don’t work in the older Flash
player version you selected are grayed out.
In fact, if, after you select an older Flash
player, you attempt to access a grayed-out,
off-limits feature such as 9-slice, you are
presented with a dialog box and the option to
revisit your Publish Settings (as shown in
Figure 1.9).
FIGURE 1.9
Flash informs you when a feature is off-limits
to the Flash player you’re targeting.
Although you, the developer, undoubtedly
want to require your users to upgrade to Flash
player 8 so you can use all the cool new
features, your boss, client, or customers might
not be so eager to upgrade their browser plug-
ins to Flash player 8. On one hand, I under-
stand this reality. It’s going to be a matter of
time before Flash player 8 is an accepted
minimum requirement for websites. However,
it’s also important that you educate your boss,
client, or customers.
Express Install is not the only upgrade
approach and has its drawbacks, such as
needing to first check which version the user
has and creating a Flash player 6
.swf
to
perform the Express Install. Just read the 25-
page document and associated sample files
in the Flash Deployment Kit (www.
macromedia.com/go/fp_detectionkit), and
you’ll learn all the available options. I
predict that this Express Install feature, along
with the killer features such as filters and
video, will greatly accelerate the adoption
rate for Flash 8 (historically taking 12
months for a new player version to reach
80% of all Internet users).
ActionScript Additions
17
The express install is simply the most advanced option
available because it performs the install from within
the older Flash player.Traditional ways of upgrading
users still exist.For example, the default
.html
gener-
ated when you publish automatically presents the user
with a traditional Active X install dialog box in Internet
Explorer or the Missing Plug-ins button in Netscape
and Firefox.
NOTE
Flash Professional 8 and Flash Basic 8
I suppose this is a bit of a sour way to end an
otherwise exciting section about what’s possi-
ble with Flash 8, but I have to explain the
differences between the two versions of the
Flash 8 product. Unlike the confusing and
subtle differences between Flash MX 2004 and
Flash MX 2004 Professional, the split between
Flash Professional 8 and Flash Basic 8 is
profound. In a nutshell, the only reason to
purchase Flash Basic is if you need supple-
mental copies for machines dedicated for
some sort of Flash assembly line. Macromedia
says Basic is for the “occasional user,” which
is accurate if you don’t plan on using most of
the new Flash 8 features, including using the
Flash interface to control filters or blends,
producing videos that use the new On2 VP6
codec, and using advanced FlashType text
settings—none of which are fully supported
in Flash Basic.
Granted, Flash Basic is almost half the price
of Flash Professional. But it’s not even that
easy to purchase it. You can’t purchase Basic
as part of Macromedia Studio 8 (the bundle
that also includes Dreamweaver, Fireworks,
and Contribute). And all upgrades from any
older version of Flash lead to Flash
Professional. Ultimately, the only good
feature in Flash Basic is the fact there’s an
integrated upgrade system to turn your
version of Basic into Flash Professional 8.
ActionScript Additions
ActionScript hasn’t gotten the same facelift it
did when AS2.0 was introduced in Flash
MX2004. Nevertheless, there are some pretty
major additions to the ActionScript feature
list—too many, in fact, to list them all here.
However, I’ll list the major new features in
the following sections because most appear
in later chapters (even if the appearance is
often hidden away in the support files).
A Programming Primer
Because the section that follows this section
covers new ActionScript features, you’ll find it
peppered with terms such as variables,
instances, and properties. If this kind of infor-
mation is familiar to you, feel free to skip
ahead to the next section (on the
flash.filters
package). If such terms are
new to you, you’ll find additional definitions
for such terms in the Glossary (as well as in
underscore in their names). Movie clip
instances are the easiest type of object to
understand because you can see them. But
there are also instances of the Sound and
Date classes—just to name two.
Chapter 2). However, instead of having you
keep one thumb in the Glossary while you
read this chapter, here’s a narrative defini-
tion of the terms that appear throughout the
rest of this chapter and the book. Let me
stress two things before I start: First, if you
find this material basic, don’t worry, I
promise you’ll get plenty of opportunities to
adapt the projects in this book and flex your
programming skills. (I won’t treat anyone
like a baby.) If, on the other hand, this mate-
rial is totally new to you, this explanation
will only provide an introduction to the
terms I use in this book. I don’t suspect this
quick lesson will turn you into a hardcore
programmer, but at least you can follow
along when I explain the code behind the
scenes of each project. You don’t have to add
any custom programming to build the proj-
ects, but you can. And for me to explain
what’s going on, I have to use a program-
mer’s vocabulary.
It’s easiest to start with the most common
object type, movie clips, because they have a
visual representation on stage. A movie clip
symbol on stage is called an instance. You
can give each instance on stage a unique
instance name by using the Properties panel.
The instance name is used in your
ActionScript code to refer to the clip—or,
more technically, to address the clip. The
reason you don’t use the symbol name (from
the master Movie Clip symbol in the Library)
is because you might have multiple instances
of that same symbol on stage and you want
to address each one individually. Why would
you want to address a clip? Usually to
change one of its properties such as its posi-
tion on stage (either its
_x
property or
_y
property, although there are many other
properties and they don’t always have an
CHAPTER 1: Exploring Flash 8
18
I capitalized
Sound
and
Date
because, when you
create an instance of these object types, you must use
the exact, case-sensitive spelling.
NOTE
Think of this analogy: People have properties
(such as hair color, weight, and age) and cars
have properties (such as horsepower, make,
and model). Interestingly, sometimes two
different object types share the same property.
Cars and humans both have a weight prop-
erty. Similarly, movie clip instances and
button instances both have a
width
property.
Often, however, the available properties
depend on the type of object you’re working
with. Sound instances have a
duration
prop-
erty, but movie clip instances don’t.
The good news is that the code you write to
address clips and their properties uses the
same form (or syntax) in every case regardless
of the object type. Namely, the syntax to refer
to an instance’s property always looks like
this:
myInstance.myProperty
(or “object dot
property”). I use the prefix
my
to indicate
something I made up so you don’t think the
terms
myInstance
or
myProperty
are built in
to ActionScript. Note that sometimes you
want to set a property (perhaps set a clip
instance’s
_rotation
property to make it
spin); other times you’ll just need to get a
property’s value to use within a larger
statement. (A statement is a complete
instruction—basically one line of code.)
Check out this example:
myClip._x = otherClip._x
When Flash encounters this line of code, it
interprets the code and executes the instruc-
tions (meaning it does what the code says to
do). In this example, the instance called
myClip
gets its
_x
property set to a value
equal to the
_x
property of another instance
called
otherClip
. (Anytime you see a single
equals sign, it’s an assignment meaning “is
now equal to,” as in “
myClip
’s
_x
is now
equal to
otherClip
’s
_x
”.) Notice that you’re
setting the
_x
property of
myClip
but only
getting the property of
otherClip
.
Another important concept is methods.
Methods are like processes or procedures
applied to a single instance. You can also
think of methods as the capabilities a partic-
ular object type supports. Back to the human
analogy: walk, talk, and comb your hair are
all methods—they’re all things an instance of
a human being is capable of doing. Methods
you can apply to movie clip instances
include
play()
,
stop()
, and
gotoAndPlay()
. I
like to compare properties to methods
because their syntaxes are nearly identical.
It’s always “object dot method,” as in
myClip.play()
. An easy way to distinguish
methods is that they always have parenthe-
ses. Some methods accept parameters (also
called arguments) that provide needed addi-
tional details. For example, when you say
myClip.gotoAndPlay(1)
,
1
is a parameter
indicating which frame you want to go to.
Events are things that happen while a Flash
movie plays. The most intuitive event types
are things the user does, such as clicks, drags,
ActionScript Additions
19
or presses a key. Naturally, there are all kinds
of events, and like properties and methods,
events vary depending on the object type. For
example, Sound instances trigger or fire
events when the event
onSoundComplete
is
encountered (that is, when the sound ends).
A button instance has an
onPress
event (but
no
onSoundComplete
event). Just as trees can
fall in the woods without anyone to hear
them, events can fire in Flash and—unless
your code is listening for that event—they go
unnoticed. You have to write code to trap (or
listen for) an event and define exactly how
you want to handle that event. What’s a little
freaky is that events are really properties to
which you assign a value. Just as you might
say
myClip._x = 100
(to make the clip
appear at the x position of 100), you
could say
myClip.onEnterFrame =
myAnimationFunction
—that says the
myClip
’s
onEnterFrame
event (which fires every 1/12 of
a second if your frame rate is 12 fps)
is now equal to something called
myAnimationFunction
. In both cases, a prop-
erty (
_x
or
onEnterFrame
) is assigned a value.
In this case, the value of the
_x
property is
assigned a value in the data type
Number
. If
you were to assign the
label
property for a
Button component, you would want to use a
value of the data type
String
. The value you
assign to an event is of the type
Function
.
You can create variables as a way to store
data for later use. For example, you could
assign a variable’s value with this code:
myName = “Phillip”
(which means the vari-
able named
myName
is now equal to the string
“Phillip”
). You can change the value of a
variable by simply reassigning a value, but
at any one instant, a variable has a single
value. You can store any data type in your
variable, but you’ll often want to type your
Sometimes the class you instantiate is part of
Flash and other times the definition for its
behavior resides in a class file (
MyClass.as
,
for example). For instance, I created an
EventChannel
class (in a file named
EventChannel.as
) for Chapter 3. You create
an instance by using the following syntax:
myECInstance = new EventChannel();
After you have an instance of a class stored
in a variable, you can do anything you want
with that instance. That is, the class will
probably expose public methods, which are
methods you’re allowed to access and trigger.
Just as you can say
myMovieClip.play()
,
you can also say
myECInstance.
startMonitoring()
because I defined a
public method called
startMonitoring()
.
(Exactly what happens when that method
gets triggered depends on what the program-
mer designed the class to do.) I should note
that private methods can be triggered only
from within the class itself; they are like
internal utilities to help the class do its work.
Many times, you need to reference a class’s
complete path, as in this example:
myInstance = new
foldername.subfolder.MyClass()
I’ll discuss class paths in Chapter 2, but just
realize that there may be a
MyClass
class in
the previous path shown and another—
completely different—version of the same
name in another path. There’s no conflict
because the code doesn’t refer to
MyClass
but
rather to
foldername.subfolder.MyClass
.
Think how we have a president (like the
variables—that is, to define the variable with
the data type it is allowed to contain. Here is
an example of typing the
myName
variable as
a
String
data type:
var myName:String = “Phillip”;
The reason you type a variable is simply so
that Flash will give you a warning when you
publish if you write code that tries to assign a
value that doesn’t match the data type you
declared. That way, Flash helps you uncover
mistakes in your code.
CHAPTER 1: Exploring Flash 8
20
In future versions of the Flash player, typing your vari-
ables will make your projects perform much faster.
NOTE
Finally, terms such as object and class are
thrown around a lot, but they’re actually
quite simple. I’ve been talking about movie
clip instances because they’re so common,
but they’re actually instances of the class
MovieClip
. You could say that their object
type is
MovieClip
. Instances of the class
MovieClip
are easy to understand because
you make an instance by simply dragging the
symbol from the Library onto the stage. For
most other object types, you must formally
instantiate them (as in “make an instance
of”). You always instantiate an instance of a
class by using this syntax:
myInstance = new MyClass()
You replace
MyClass
with the class you’re
instantiating. (By convention, all class names
begin with an uppercase character.)
ActionScript Additions
21
code applies a
BlurFilter
with a factor of
50
to a clip instance named
myClip
when the
user clicks the stage; it then applies a differ-
ent filter, with a factor of
5
, when the user
lets go:
onMouseDown = function(){
var veryBlurry =
new flash.filters.BlurFilter(50,50);
myClip.filters = [ veryBlurry ];
}
onMouseUp = function(){
var lessBlurry =
new flash.filters.BlurFilter(5,5);
myClip.filters = [ lessBlurry ];
}
The
flash.filters
package lets you create
any kind of filter the Filters panel can create,
but you do it with ActionScript so it can
respond to any event, such as the user’s
mouse movement. One other thing to note is
that movie clip instances in Flash 8 have a
filters
property.
In addition to ActionScript equivalents to all
the filters in the Filters panel, ActionScript
offers three other classes (in the
flash.filters
package) for even more
advanced effects—namely,
ColorMatrixFilter
,
DisplacementMapFilter
,
and
ConvolutionFilter
. You’ll learn more
about these in Chapter 9, “Creating Special
Effects.” They’re identical to the
flash.filters
package in that you still
apply them to the
filters
property, but the
way in which you create them is much more
involved.
president of the United States), but you can
also have the Portland Cactus Collectors
President—and they reference different posi-
tions. A class path is like a qualifier.
With your ActionScript primer out of the way,
we will move onto the key new ActionScript
features in Flash 8.
The flash.filters Package
Filters can be applied using the Filters panel
(while authoring) or using ActionScript code.
This enables you to write scripts that modify a
filter’s effect at runtime. For example, you
could make some text get blurrier as the user
moves the mouse away and sharper as the
mouse moves closer. Writing the code to
apply a filter at runtime is a two-step process.
First, you create a filter instance and store it
in a variable. Second, you apply the filter to a
movie clip instance through its
filters
prop-
erty. If you want to change the filter applied
to a clip, you simply modify the filter or
create another filter with different properties
and (in either case) overwrite the clip’s
filters
property. Here’s a simple example in
which we apply a blur filter to a movie clip
instance named
myClip
:
myFilter = new flash.filters.BlurFilter();
myClip.filters = [ myFilter ];
Notice that the filters property is assigned an
array that contains just one item (
myFilter
).
By putting more filters in the array you can
apply more than one filter. In addition, you
can set various parameters when you first call
the
BlurFilter()
function to affect how
much of a blur you want. For example, this